Go Down

Topic: help with dataflash library example (Read 1 time) previous topic - next topic

fbriggs4

I am attempting to use the dataflash library from the playground which can be found here http://playground.arduino.cc/Code/Dataflash I have an AT45DB081D (data sheet here) http://www.atmel.com/Images/doc3596.pdf  on a break out board and connected to my UNO with VCC going to the 3.3V output and the rest go to the locations specified in the library. I am trying to get the example to run so that I can build off of that. I initially got compile errors because of WProgram.h so I changed that to Arduino.h since I am using IDE 1.0. Then I got compile errors because BYTE is no longer supported so I removed that and then everything compiled. However, it gets to a while loop and appears to hang. I posted the sketch right up to the point where it hangs and I notated it in the code where I get to. I also tried the library in its original format with IDE 0023 with the same results. I also tried a second AT45DB081D on a breadboard Arduino running an 8mhz internal clock which also gave the same results.

Code: [Select]

#include <dataflash.h>

int lastpage=0; //last page written to
int pages=5; //total pages that will be used changed from 25 to 5
Dataflash dflash;

void setup()
{
  Serial.begin(115200);
  Serial.print('h');
  Serial.print('i');
  Serial.print('\n');//debug
  dflash.init(); //initialize the memory (pins are defined in dataflash.cpp
}

void loop()
{
  int j = 0;
  int i = 0;
  char messageline[] = "This is only a test on page: ";
  char lpstring[] = "lastpage: ";
  char int_string[10];

  itoa(lastpage, int_string, 10); // make string of the pagenumber
  strcat(messageline, int_string); //append to the messagline string
  //for (int i=0; messageline[i] != '\0'; i++){
  while (messageline[i] != '\0'){
    Serial.print(messageline[i]); //This prints the first letter of the array and then stops
    dflash.Buffer_Write_Byte(1, i, messageline[i]);  //it seems to get hung here and it does not loop through
    Serial.println("transmitting"); //this never prints so I assume it gets hung above
    j = i;
    i++;
  }


Code: [Select]

//my output looks like this

hi
T


I have never seen a while loop hang before so I am a little lost as to what to try next. Any suggestions on how I can troubleshoot this are appreciated.




PaulS

Quote
I have never seen a while loop hang before

Which while loop do you think is hanging? I don't think that is your problem.

Code: [Select]
  char messageline[] = "This is only a test on page: ";
  char lpstring[] = "lastpage: ";
  char int_string[10];

  itoa(lastpage, int_string, 10); // make string of the pagenumber
  strcat(messageline, int_string); //append to the messagline string

messageline is exactly large enough to hold the text you provided and the trailing NULL. There are exactly 0 bytes extra, in which you try to store at least one more byte. Fail.

Now that you have stomped on memory you don't own, unpredictable results will occur. It is not even worth the effort to read further. You absolutely MUST fix this problem before we can even think about looking at the rest of the code.

fbriggs4

PaulS- I made the suggested change to the array and initialize it with plenty of extra room. This unfortunately had no effect. I spent more time going over everything I realized that I had incorrectly introduced Arduino.h into the library and fixing that helped somewhat. Then I spent some more time reading the datasheet and trying things which has also netted some results. According to the library Pins 3 (reset) and pin 5 (WP) should be put into Arduino digital pins 7 and 8 which is what I had been doing. When I had it wired like this the while loops would usually hang. Based on the data sheet these should be run to VCC so I connected them to the 3.3V pin on the Arduino. Moving WP and reset to VCC had a big impact and suddenly the while loops were not getting hung. The issue I seem to have now is that I am getting all zeros back when reading the buffer. I am not sure how to diagnose if the issue on the read side or if I am not getting the data stored. Any suggestions on how to do this are appreciated!

PaulS

Quote
I made the suggested change to the array and initialize it with plenty of extra room. This unfortunately had no effect.

I can't see the changes that you made.

fbriggs4

Here is the block of code that I changed, the rest is the same.

Code: [Select]

  char messageline[35] = "this is only a test on page: ";
  char lpstring[15] = "lastpage: ";
  char int_string[10];



Code: [Select]

//here is the output I am getting. I was getting all zeros and today I get 255 and I cant explain why.
This is only a test on page: 0 lastpage: 0
This is only a test on page: 1 lastpage: 1
This is only a test on page: 2 lastpage: 2
This is only a test on page: 3 lastpage: 3
This is only a test on page: 4 lastpage: 4
This is only a test on page: 5 lastpage: 5
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255  page: 32

Go Up