Go Down

Topic: Dataflash memory (Read 2050 times) previous topic - next topic

bigengineer

Jul 18, 2007, 07:25 pm Last Edit: Jul 18, 2007, 07:26 pm by bigengineer Reason: 1
I added a library to the playground for interfacing with the atmel dataflash memory.
After trying lots of different things this was the easiest way to add some memory to the arduino. It doesn't have a filesystem so you to think for yourself about the memory usage. I added a very simple example to the library so you can check if it works. After that your are on your own.  But comments, additions and improvements are always welcome.

This library is based on code for the Atmel butterfly. It was changed by Martin Thomas to compile with gcc. I only changed it to C++ to make a library for it.

HULK

#1
Nov 08, 2008, 08:01 am Last Edit: Nov 08, 2008, 08:03 am by HULK Reason: 1
Anybody done any testing with this library?
If so please share your results and maybe a pice of your code as an example.

zumbi

My results compiling the example under arduino-0012,
Quote

In file included from dataflash.cpp:50:
dataflash.h:70: warning: only initialized variables can be placed into program memory area
dataflash.h:71: warning: only initialized variables can be placed into program memory area
In file included from /home/zumbi/ELECTRONICS/ARDUINO_SOFT/tmp/arduino-0012/hardware/cores/arduino/WProgram.h:4,

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:80: error: expected unqualified-id before 'int'

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:80: error: expected `)' before 'int'

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:80: error: expected `)' before 'int'

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:111: error: expected `)' before 'int'

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:111: error: expected `)' before 'int'

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:144: error: expected identifier before '(' token

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:144: error: expected `)' before '(' token

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:144: error: expected ',' or '...' before '(' token

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:144: error: expected initializer before ')' token

/usr/lib/gcc/avr/4.3.2/../../../avr/include/stdlib.h:176: error: '__compar_fn_t' has not been declared

In file included from /home/zumbi/ELECTRONICS/ARDUINO_SOFT/tmp/arduino-0012/hardware/cores/arduino/WProgram.h:6,


mikalhart

Zumbi--

See http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222985221/2

Mikal

HULK

Found it .

Did not know that there is an example code in the zipped download content for this library at the playground.
Here it is for those that are lazy  :)

Code: [Select]

#include <dataflash.h>

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

void setup()
{
 Serial.begin(115200);
 Serial.print('h',BYTE);
 Serial.print('i',BYTE);
 Serial.print('\n',BYTE);//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], BYTE); //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
}




xDev

Hi,
I just test this code lib but found error as below (Arduino0016)

In file included from C:\arduino-0016\hardware\cores\arduino/WProgram.h:4,


c:/arduino-0016/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'


c:/arduino-0016/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/arduino-0016/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


In file included from C:\arduino-0016\hardware\cores\arduino/WProgram.h:6,

please help....


todotani

Hi,
Add the following line at the top of dataflash.h
#include <WProgram.h>

Sample sketch (dataflash_intro.pde) worked with my AT45DB161D.
However, if you have D version like AT45DB161D, lot of commands have been changed/added on D version.

You can fined library for AT45DB161D at the following blog;
http://blog.blockos.org/?p=27

Go Up