FlashShield Simple Sample Sketch

Postings related to the FlashShield device.

FlashShield Simple Sample Sketch

Postby GregEigsti » Sat Mar 20, 2010 5:01 pm

A few notes:
  • 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
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1075
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: FlashShield Simple Sample Sketch

Postby spidermonkey04 » Tue Apr 06, 2010 10:36 am

The read_id() function in dataflash.cpp needs a DF_CS_inactive() at the beginning.

Is anybody using the flash successfully? I've only been testing for one night, but when I write a byte to either buffer then read it back, it's different. Maybe it's the write function? I think I was just trying the number 5(byte) and it goes into the buffer as something else. I could write that buffer to a page and read the page back, but it was still that 'something else'.

Any ideas?

---Jared
spidermonkey04
 
Posts: 70
Joined: Thu Oct 29, 2009 6:45 pm

Re: FlashShield Simple Sample Sketch

Postby spidermonkey04 » Thu Apr 08, 2010 12:49 pm

The current StatusReg (0x57) doesn't seem to play nice when looking at the ready/busy flag. Changing this to 0xD7 in dataflash.h seems to fix it.
Code: Select all
#define Buf2Read         0xD6   // Buffer 2 read
#define StatusReg         0xD7   // Status register

I was trying to erase a dozen pages in a loop using the Page_Erase() function. It wasn't erasing them all, and it seems not waiting for the busy flag is to blame.
Code: Select all
while(!(Read_DF_status() & 0x80));            //monitor the status register, wait until busy-flag is high

Is this an OK place to talk about changes?

---Jared
spidermonkey04
 
Posts: 70
Joined: Thu Oct 29, 2009 6:45 pm

Re: FlashShield Simple Sample Sketch

Postby GregEigsti » Thu Apr 08, 2010 5:15 pm

Cool stuff.
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1075
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: FlashShield Simple Sample Sketch

Postby spidermonkey04 » Thu Apr 15, 2010 12:56 pm

In Read_DF_status(), this is being called to get the chip density (16Mbit) so we know what the PageSize should be.
Code: Select all
index_copy = ((result & 0x38) >> 3);   //get the size info from status register
  // mtA
 
  PageBits   = pgm_read_byte(&DF_pagebits[index_copy]);   //get number of internal page address bits from look-up table
  PageSize   = pgm_read_word(&DF_pagesize[index_copy]);   //get the size of the page (in bytes)

However, the Read_DF_status() function can be called numerous times in a write operation. I don't think we need to fetch the chip density more than once (in init() maybe), if at all. I'd prefer to just put the PageSize in a #define in dataflash.h and comment out the PROGMEM string.
Code: Select all
#define PageBits 10
#define PageSize 528
//const uint8_t DF_pagebits[] PROGMEM ={9,  9,  9,  9,  9,  10,  10,  11};
//const uint16_t DF_pagesize[] PROGMEM ={264,264, 264, 264, 264, 528, 528,1056};

This way, Read_DF_status() is simple and fast. Plus we don't use unnecessary PROGMEM space.
Code: Select all
unsigned char Dataflash::Read_DF_status (void)
{
  unsigned char status;
  DF_CS_inactive();  //Toggle CS pin to reset Dataflash command decoder
  DF_CS_active();
  DF_SPI_RW(StatusReg);  //Status Register Read op-code
  status = DF_SPI_RW(0x00);  //Dummy write to get result
 
  return status;
}

Also, I've been working on getting WiServer talking to the Dataflash. Things are looking good and I'll post it up in a few days. I'm liking this chip, the only problem I see is getting your data (images, webpages) onto it. I think I have a solution though...

Is anyone working on the Wiki article?

---Jared
spidermonkey04
 
Posts: 70
Joined: Thu Oct 29, 2009 6:45 pm

Re: FlashShield Simple Sample Sketch

Postby GregEigsti » Thu Apr 15, 2010 4:43 pm

Good stuff, I have not been playing with the data flash since I don't have a need for it (currently). Looking forward to picking your brain :D

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1075
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website


Return to FlashShield 1.0

Who is online

Users browsing this forum: No registered users and 1 guest

cron