PaulS- here is all the code. One thing I did notice is that there is a Serial.print('\t'): which never prints in the output. I am not sure what that means but I suspect it is significant.
#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.write('h');
Serial.write('i');
Serial.write('\n');//debug
dflash.init(); //initialize the memory (pins are defined in dataflash.cpp
}
void loop()
{
char messageline[35] = "This is only a test on page: ";
char lpstring[15] = "lastpage: ";
char int_string[10];
itoa(lastpage, int_string, 10); // make string of the pagenumber
strcat(messageline, int_string); //append to the messagline string
int j = 0;
int i = 0;
while (messageline[i] != '\0'){
Serial.write(messageline[i]); //just a check to see if the loop is working
dflash.Buffer_Write_Byte(1, i, messageline[i]); //write to buffer 1, 1 byte at the time
j = i;
i++;
}
i=0;
dflash.Buffer_Write_Byte(1, j+1, '\0'); //terminate the string in the buffer
Serial.print('\t');
dflash.Buffer_To_Page(1, lastpage); //write the buffer to the memory on page: lastpage
strcat(lpstring, int_string);
for(int i=0; lpstring[i] != '\0';i++)
{
dflash.Buffer_Write_Byte(2, 20, lpstring[i]); //write to buffer 2 the lastpage number that was used
Serial.print(lpstring[i]); //write to serial port the lastpage number written to
}
Serial.println();
lastpage++;
if (lastpage > pages) //if we reach the end of the range of pages
{
lastpage = 0;
for (int i=0;i<=pages;i++)
{
dflash.Page_To_Buffer(i, 1);//copy page i to the buffer
for(int j=0;j<32;j++) //32 depends on the amount of data on the page
// testing for a specific charater is also possible
{
Serial.print(dflash.Buffer_Read_Byte(1, j)); //print the buffer data to the serial port
}
Serial.print(" page: ");
Serial.println(i); //print the last read page number
}
}
delay(200); //slow it down a bit, just for easier reading
}
Here is the output based on the code above.
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: 0
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255 page: 1
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255 page: 2
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255 page: 3
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255 page: 4
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255 page: 5