- This was developed/tested on the FlashShield, have not yet tackled the WiShield 2.0 (which also has the flash)
- Currently the dataflash sources only support "Buffer 1"; supporting both buffers should be possible with some work
- I have only played with writing to the buffer, and not the page. I still have not completely grokked the memory architecture of this flash (would be a good wiki article).
- The flash hardware supports far more operations than the dataflash library supports - good opportunity for community improvement for this library
- I ran into the issue that the Mfgr/Dev IDs come back correct before my first write to the buffer and change after that first write. The sample sketch clearly shows this.
- The sample sketch reads/writes a single byte as well as a str (unsigned char array). Like I said there is a lot more available!
Neat stuff!!! On to the WS2.0!!!
WS2.0 version of this script at: http://asynclabs.com/forums/viewtopic.php?f=23&t=269
Also, I have updated a couple of values in dataflash.h - the datasheet said that the current values were deprecated and to use the specified new values (which I found to be more reliable anyway).
- Code: Select all
#define Buf1Read 0xD4 // Buffer 1 read
#define Buf2Read 0xD6 // Buffer 2 read
- Code: Select all
//AsyncLabs FlashShield Test Sketch
#include <dataflash.h>
//currently only memory buffer 1 is enabled in the dataflash library
#define MEMBUFFER 1
#define PAGEADDR 0
#define FLASH_SLAVE_SELECT 10
#define BUFFERSIZE 32
unsigned char count;
void setup()
{
count = 0;
Serial.begin(115200);
dflash.init(FLASH_SLAVE_SELECT);
}
void loop()
{
unsigned char mfg_id[4];
unsigned char buffer[BUFFERSIZE];
//print flash device mfg/dev ID
//this value changes after the first write
Serial.println("---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---");
dflash.read_id(mfg_id);
Serial.print(" Mfg ID: ");
Serial.println(mfg_id[0], HEX);
Serial.print(" Dev ID: ");
Serial.print(mfg_id[1], HEX);
Serial.println(mfg_id[2], HEX);
//clear out the data buffer
memset(buffer, 0, BUFFERSIZE);
//print the flash data (byte and string) pre-update
Serial.println("---=== Flash Data byte/str contents ===---");
Serial.print(" byte: ");
Serial.println(dflash.Buffer_Read_Byte(MEMBUFFER, PAGEADDR), DEC);
Serial.print(" str : ");
dflash.Buffer_Read_Str(MEMBUFFER, PAGEADDR+1, BUFFERSIZE, buffer);
Serial.println((char*)buffer);
//clear out the data buffer
memset(buffer, 0, BUFFERSIZE);
//update the flash data (byte, str)
Serial.println("---=== Updating Flash Data ===---");
sprintf((char*)buffer, "Iteration: %d", count);
dflash.Buffer_Write_Byte(MEMBUFFER, PAGEADDR, count++);
dflash.Buffer_Write_Str(MEMBUFFER, PAGEADDR+1, strlen((const char *)buffer)+1, buffer);
Serial.println();
delay(1000);
}
Greg