Show Posts
|
|
Pages: [1] 2 3 ... 6
|
|
1
|
Using Arduino / Storage / Re: AT45DB dataflash library problems with timer2 interrupt
|
on: March 05, 2013, 11:37:58 pm
|
I was actually able to get it working, but I am not 100% sure why. What I have found is that I need to transmit the page twice in order for it to write the buffer to the memory. For example this works i = 0; while (i < 60){ dflash.Buffer_Write_Byte(1, i, messageline[i]); //write to buffer 1, 1 byte at a time i++; } dflash.Buffer_To_Page(1, page); //write the buffer to the memory on page: page dflash.Buffer_To_Page(1, page); //write the buffer to the memory on page: page }
This does not work. i = 0; while (i < 60){ dflash.Buffer_Write_Byte(1, i, messageline[i]); //write to buffer 1, 1 byte at a time i++; } dflash.Buffer_To_Page(1, page); //write the buffer to the memory on page: page }
Any idea why writing the page twice would work? Maybe I need to send more don't care bits?
|
|
|
|
|
3
|
Using Arduino / Storage / Re: Using the writeAnything utility without struct
|
on: February 08, 2013, 09:30:03 am
|
|
I have used it with individual variables and it works fine. You just need to make sure not to put 2 variables at the same EEPROM address and you have to space the address far enough apart to not step on each other. But otherwise it works fine.
|
|
|
|
|
6
|
Using Arduino / Storage / Re: AT45DB dataflash library problems with timer2 interrupt
|
on: February 06, 2013, 05:33:30 pm
|
I misunderstood your question the first time, hopefully this answers you properly. This is the complete sketch with the interrupt handler included. #include <dataflash.h>
int page = 0; int buffer = 1; char messageline[60] = "#This is a test string for the flash memory"; char readFlash[60]; Dataflash dflash; int i = 0; volatile int seconds = 0; //used to keep time
SIGNAL(TIMER2_OVF_vect){ seconds++; }
void setup(){ //Setup TIMER2 TCCR2A = 0x00; TCCR2B = (1<<CS22)|(1<<CS21)|(1<<CS20); //Set CLK/1024 or overflow interrupt every 8s ASSR = (1<<AS2); //Enable asynchronous operation, 32kHz xtal needed TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt. If this is disabled the sketch works properly sei(); //Enable global interrupts pinMode(A3, OUTPUT); //Flash VCC digitalWrite(A3, HIGH); //powers the flash memory up delay(4000); Serial.begin(9600); Serial.println("starting the sketch now"); dflash.init(); //initialize the memory (pins are defined in dataflash.cpp }
void loop(){ writeData(); readData(); page++; delay(1000); //keep it from running so quickly in testing }
void writeData(){ Serial.print("I am writing page "); Serial.println(page); i = 0; while (i < 60){ dflash.Buffer_Write_Byte(1, i, messageline[i]); //write to buffer 1, 1 byte at a time i++; } dflash.Buffer_To_Page(1, page); //write the buffer to the memory on page: page }
void readData(){ Serial.print("reading page "); Serial.println(page); dflash.Page_To_Buffer(page, buffer);//copy page to the buffer i = 0; while(i < 60){ readFlash[i] = dflash.Buffer_Read_Byte(buffer, i); //read the buffer i++; } Serial.println(' '); Serial.println(readFlash); //print what was read from the buffer }
|
|
|
|
|
7
|
Using Arduino / Storage / Re: AT45DB dataflash library problems with timer2 interrupt
|
on: February 06, 2013, 05:11:41 pm
|
|
Sorry if it came across the wrong way but I really do need help. I need to get the external flash memory working on my project and I am at a loss on how to do that. During my original post I thought the only issue was the interrupts. However, I continued to test and found additional issues with the library such as if I try to write to page 6 it appears to write to page 3. It is not clear to me if I am writing to the wrong page or reading from the wrong page (or possibly both). I do not understand enough of the library to make the modifications to get it working. I am only guessing as to where the issue is but a reasonable place to start seemed to be with how the library assigns the page to memory. My problem is that despite the simplicity of the library I don't understand it. If you have suggestions on how to get the library working for my particular application or if you can suggest some reading I would greatly appreciate it!
|
|
|
|
|
8
|
Using Arduino / Storage / Re: AT45DB dataflash library problems with timer2 interrupt
|
on: February 06, 2013, 08:55:15 am
|
this enables the timer 2 interrupt. TIMSK2 = (1<<TOIE2); If I change that to zero the problem goes away. Until I find a better solution what I have done for the moment is to disable global interrupts at the start and enable them right after I write using cli() and sei() like this. void writeData(){ Serial.print("I am writing page "); Serial.println(page); cli(); //disable interrupts i = 0; while (i < 60){ dflash.Buffer_Write_Byte(1, i, messageline[i]); //write to buffer 1, 1 byte at a time i++; } dflash.Buffer_To_Page(1, page); //write the buffer to the memory on page: page sei(); //enable interrupts }
However, since this post I have found more issues. The dataflash library was created for the AT45DB041B memory which is the older 4 megabit "B" version. I am using the newer 8 megabit "D" version. The legacy B commands still work on the D, but I think I have some issues because of the memory size difference. For example when I try to store the buffer to page 6 it appears to write the data on page 3 instead. I am guessing that the library calculates the internal memory based on the 4 megabit version and that the 8 megabit version is different. I looked through the library and found the section that deals with writing the buffer to the page. I can see where it calculates the upper and lower part of the address but I don't know how to interpret it. I cant figure out where it gets "pageBits" from and what does ">>" mean? void Dataflash::Buffer_To_Page (unsigned char BufferNo, unsigned int PageAdr) { DF_CS_inactive(); //make sure to toggle CS signal in order DF_CS_active(); //to reset Dataflash command decoder if (1 == BufferNo) //program flash page from buffer 1 { DF_SPI_RW(Buf1ToFlashWE); //buffer 1 to flash with erase op-code DF_SPI_RW((unsigned char)(PageAdr >> (16 - PageBits))); //upper part of page address DF_SPI_RW((unsigned char)(PageAdr << (PageBits - 8))); //lower part of page address DF_SPI_RW(0x00); //don't cares }
|
|
|
|
|
9
|
Community / Gigs and Collaborations / paid support required for dataflash memory library
|
on: February 05, 2013, 09:26:05 am
|
I am working with some AT45DB081D flash memory and I need some help which I am prepared to pay for. The issue I have is that I am using the dataflash library which you can find here. http://playground.arduino.cc/code/dataflashThis library was developed for the AT45DB041B which has less memory and is an older version. The newer D version has more command options, although the documentation I find suggests that the legacy "B" commands are still supported. The general work flow for this memory is that if you want to write some data you first write the data to a buffer and then write that buffer to a page in memory. The problem I have is that if I specify for it to write to page 6 it will write to some other page like page 3 for example. I suspect the issue is in how the library calculates the address for the page since it was designed for a different size memory. Please PM me if you can help me update the library.
|
|
|
|
|
10
|
Using Arduino / Storage / AT45DB dataflash library problems with timer2 interrupt
|
on: February 01, 2013, 06:24:50 pm
|
I am working with the dataflash library for the AT45DB series of flash memory which can be found here. http://playground.arduino.cc/code/dataflashI have the library working perfectly in some simple sketches but when I try to add it to my main code it becomes erratic and inconsistent. For example sometimes it wont write the page, it will fail to read pages sometimes, sometimes it will read a buffer but part of it. The errors are all over the place. I am running a breadboard ATMEGA328P with the internal 8mhz oscillator and have a external 32.768 crystal. I use the external crystal to keep time and as an interrupt from sleep. A process of elimination has revealed that the cause of my problems is the timer2 interrupt. If I disable the timer2 interrupt my problems go away and the AT45DB works perfectly. In the sketch below I have it set to write the string from messageline into page 0. This loop will increment to the subsequent page and keep writing every page in the memory. This sketch example will consistently make it to page 3 and then hang for a a few seconds and then starts back at page 0. It does not seem to reset since I don't get the print statement from setup(), it just seems to start back from zero in the main loop which is quite strange. When I disable timer2 interrupt this sketch runs perfectly and writes/reads pages forever as it should (or at least until it runs out of pages). My issue is that I don't want to disable timer2 even for a brief time since that will screw up my time keeping. Is there any way to keep the flash memory happy and keep my timer2 interrupt running? #include <dataflash.h>
int page = 0; int buffer = 1; char messageline[60] = "#This is a test string for the flash memory"; char readFlash[60]; Dataflash dflash; int i = 0;
void setup(){ //Setup TIMER2 TCCR2A = 0x00; TCCR2B = (1<<CS22)|(1<<CS21)|(1<<CS20); //Set CLK/1024 or overflow interrupt every 8s ASSR = (1<<AS2); //Enable asynchronous operation, 32kHz xtal needed TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt. If this is disabled the sketch works properly sei(); //Enable global interrupts pinMode(A3, OUTPUT); //Flash VCC digitalWrite(A3, HIGH); //powers the flash memory up delay(4000); Serial.begin(9600); Serial.println("starting the sketch now"); dflash.init(); //initialize the memory (pins are defined in dataflash.cpp }
void loop(){ writeData(); readData(); page++; delay(1000); //keep it from running so quickly in testing }
void writeData(){ Serial.print("I am writing page "); Serial.println(page); i = 0; while (i < 60){ dflash.Buffer_Write_Byte(1, i, messageline[i]); //write to buffer 1, 1 byte at a time i++; } dflash.Buffer_To_Page(1, page); //write the buffer to the memory on page: page }
void readData(){ Serial.print("reading page "); Serial.println(page); dflash.Page_To_Buffer(page, buffer);//copy page to the buffer i = 0; while(i < 60){ readFlash[i] = dflash.Buffer_Read_Byte(buffer, i); //read the buffer i++; } Serial.println(' '); Serial.println(readFlash); //print what was read from the buffer }
|
|
|
|
|
13
|
Using Arduino / Programming Questions / Re: Serial data over GSM socket connection
|
on: January 26, 2013, 02:31:45 pm
|
printing idx is a very good idea. I tried that and it does increment like it should. I get the following Arduino output and the server transmitted "VektorTek 0.1". this is idx 1 this is serialData this is idx 2 this is serialData Vthis is idx 3 this is serialData ethis is idx 4 this is serialData kthis is idx 5 this is serialData tthis is idx 6 this is serialData othis is idx 7 this is serialData rthis is idx 8 this is serialData Tthis is idx 9 this is serialData ethis is idx 10 this is serialData kthis is idx 11 this is serialData this is idx 12 this is serialData 0this is idx 13 this is serialData .this is idx 14 this is serialData 1this is idx 15 this is serialData
this is idx 16 this is serialData
Here is the entire code, it requires some explanation though. It is a bread board Arduino running 8mhz internal with a 32.768 crystal which increments the timer variable every 8 seconds. #include <SoftwareSerial.h> //used for the GPS port 5 which is GPS TX SoftwareSerial mySerial(5, 2); // RX, TX MAKE SURE TO CHANGE THE TX PORT FOR PRODUCTION
int timer = 0;
SIGNAL(TIMER2_OVF_vect){ timer++;
}
char serialData[100]; char inByte; int i = 0; int idx = 0; boolean reply = false; char hello[10] = "hello"; boolean check = false; boolean reg = false; int test; boolean IP = false; boolean banner = false;
void setup(){ mySerial.begin(9600); delay(2000); mySerial.println("testing the port"); Serial.begin(9600); pinMode(A2, OUTPUT); digitalWrite(A2, LOW); // needs to be LOW to be on, HIGH is off delay(2000); pinMode(A0, OUTPUT); digitalWrite(A0, LOW); // needs to be LOW for 3 seconds to turn on the GSM modem delay(2000); // pinMode(A0, INPUT); digitalWrite(A0, HIGH); delay(3000); //wait for the GSM modem to fully wake up before sending any commands. mySerial.println("testing the port2");
}
void loop(){ signal(); if (IP == true){ socket(); } delay(15000); //delay to keep it from looping quickly // } void socket(){ banner = false; idx = 0; timer = 0; Serial.println("AT#SKTD=0,4444,46.102.168.139"); //open the socket connection to the server mySerial.println("AT#SKTD=0,4444,46.102.168.139"); delay(1000); while (banner == false && timer < 10){ while (Serial.available() > 0){ inByte = Serial.read(); serialData[idx] = inByte; serialData[idx+1] = '\0'; idx++; mySerial.print(inByte); mySerial.print("this is idx "); mySerial.println(idx); mySerial.print("this is serialData "); mySerial.println(serialData); if (inByte == 10){ idx = 0; mySerial.println("got an LF and checking to see if the string matches"); mySerial.println(serialData); if (strncmp(serialData, "CONNECT", 6) ==0){ mySerial.println("CONNECT matched"); delay(3000); Serial.println("0123456789"); mySerial.println("0123456789"); //banner = true; //delay(2000); } if (strncmp(serialData, "Option:", 6) ==0){ Serial.println("option matched"); } } } } } void signal(){ delay(500); Serial.println("AT"); delay(1000); Serial.println("ATE0"); //disable echo delay(1000); Serial.println("AT#SIMDET=1"); //turn on the SIM card mySerial.println("AT#SIMDET=1"); // delay(2000); // Serial.println("AT\\Q0"); //disable flow control // mySerial.println("AT\\Q0"); delay(2000); Serial.println("AT+CMGF=1"); mySerial.println("AT+CMGF=1"); delay(17000); //delay to allow time for network registration Serial.println("AT+CGDCONT=1,IP,vfinternet.au"); mySerial.println("AT+CGDCONT=1,IP,vfinternet.au"); delay(2000); Serial.println("AT\\Q0"); mySerial.println("AT\\Q0"); delay(2000); Serial.println("AT#GPRS=1"); //open a GPRS connection and get an IP mySerial.println("AT#GPRS=1"); timer = 0; idx = 0; IP = false; while (IP == false && timer < 2){ while (Serial.available() > 0){ inByte = Serial.read(); serialData[idx] = inByte; serialData[idx+1] = '\0'; idx++; mySerial.write(inByte); //mySerial.print(serialData); if (inByte == 10){ idx = 0; mySerial.println("got an LF and checking to see if the string matches"); mySerial.println(serialData); mySerial.println(test); if (strncmp(serialData, "+IP: ", 4) ==0){ mySerial.println("+IP matched"); IP = true; delay(2000); } } } } }
|
|
|
|
|
14
|
Using Arduino / Programming Questions / Serial data over GSM socket connection
|
on: January 26, 2013, 01:58:19 pm
|
I am working with a Telit GSM modem and I have RX/TX and GND connected as required. Communication between the Arduino and Telit work perfectly and I can send SMS and E-mail with no problems. The serial connection transmits and receives all data perfectly under normal conditions. However, I am now doing a socket connection using the AT#SKTD command which opens a connection on a specific port on my server. When I open a socket connection the Telit goes into data mode and requires hardware flow control otherwise it wont pass any of the data to the serial. I bypass this in the software by disabling flow control. When I connect to the GSM modem directly to my computer using an FTDI I can transmit and receive properly with the server so long as I disable flow control first. However, when I connect the Arduino I get some very strange results. The Arduino can transmit perfectly and the server does receive what the Arduino outputs on the serial. I also seem to be able to receive data fro the server but the received bytes do not seem to populate into my char array. At least not in the way I expect..... If I open a socket connection the server will automatically reply and the following code is how I receive the data. For example if the server replied "Hello World" I would get the output you see at the bottom. char serialData[100]; char inByte; int idx = 0;
while (Serial.available() > 0){ inByte = Serial.read(); serialData[idx] = inByte; serialData[idx+1] = '\0'; idx++; mySerial.print(inByte); //hardware UART is used for GSM modem so I output debug data to software serial. mySerial.print("this is serialData "); mySerial.println(serialData); } //Output which clearly shows that I get "Hello World" but serialData is empty.
Hthis is serialData ethis is serialData lthis is serialData lthis is serialData othis is serialData this is serialData Wthis is serialData othis is serialData rthis is serialData lthis is serialData dthis is serialData
Since I see the "Hello World" output I know I am getting it. But for some reason it does not get populated into the array. I ONLY have this issue when I open a socket connection with the server. As soon as the socket connection is closed the Arduino populates the incoming serial data into the array as I expect. I have tried to print serialData inside the loop as you see above and outside the loop with the same results. Any suggestions on what could cause the serial to read the bye but fail to populate it into the array is greatly appreciated.
|
|
|
|
|