WiShield 2.0 Flash (non-WiFi) Sample

Postings related to the second version of the WiShield

WiShield 2.0 Flash (non-WiFi) Sample

Postby GregEigsti » Sat Mar 20, 2010 7:35 pm

A different variation of the FlashShield sample that I posted; this is a non-WiFi sample for the WShield 2.0 that shows reading/writing to the onboard flash through the dataflash library.
http://asynclabs.com/forums/viewtopic.php?f=24&t=268&p=1534#p1534

A few notes:
  • This was developed/tested on the WiShield 2.0; it is very similar to my FlashShield sample - FLASH_SLAVE_SELECT pin assignment changes and both the WiFi and flash devices are disabled at startup (to allow controlled bootstrapping)
  • 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!

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 WiShield 2.0 Flash Sample (non-WiFi)
#include <dataflash.h>

//currently only memory buffer 1 is enabled in the dataflash library
#define MEMBUFFER          1
#define PAGEADDR           0
#define FLASH_SLAVE_SELECT 7
#define WIFI_SLAVE_SELECT  10
#define BUFFERSIZE         32

unsigned char count;

void setup()
{
  count = 0;
  Serial.begin(115200);

  // there is some contention on the SPI between the flash and wifi chip,
  // so disable both devices at the beginning until they are properly
  // initialized by their respective libraries
  pinMode(FLASH_SLAVE_SELECT, OUTPUT);
  digitalWrite(FLASH_SLAVE_SELECT, HIGH);
  pinMode(WIFI_SLAVE_SELECT, OUTPUT);
  digitalWrite(WIFI_SLAVE_SELECT, HIGH);

  // now init dataflash
  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);
}
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: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: WiShield 2.0 Flash (non-WiFi) Sample

Postby 3DTOPO » Tue Jun 22, 2010 1:17 am

Thanks for the sample - this works fine - unless I try and use WiFi (udp) at the same time.

The read_id() works, but if I call Buffer_Read_Str() before WiFi.init() the WiFi online light never comes on. If I call Buffer_Read_Str() after WiFi.init(), the WiFi online comes on, but the WiFi connectivity does not work.

This code illustrates the issue below:

Code: Select all
void setup()
{
  pinMode(FLASH_SLAVE_SELECT, OUTPUT);
  digitalWrite(FLASH_SLAVE_SELECT, HIGH);
  pinMode(WIFI_SLAVE_SELECT, OUTPUT);
  digitalWrite(WIFI_SLAVE_SELECT, HIGH);
 
  dflash.init(FLASH_SLAVE_SELECT);
 
  //works
  dflash.read_id(mfg_id);
 
  //  this line will break WiFi
  //  in fact when used here, the WiFi online light never comes on
  //  dflash.Buffer_Read_Str(MEMBUFFER, PAGEADDR+1, BUFFERSIZE, prefData);
 
  WiFi.init();
 
  //  this line will break WiFi
  //  if used here instead, the WiFi online light comes on
  //  but WiFi connectivity does not work
  //  dflash.Buffer_Read_Str(MEMBUFFER, PAGEADDR+1, BUFFERSIZE, prefData);
}


It exhibits the same behavior regardless of setting WIFI_SLAVE_SELECT to 10 or 53 (which is what I believe it needs to be on for the Mega).

I have been working on this for days now, and have them both working separately, but cannot use them together which is really a bummer.

Any ideas or suggestions would be greatly appreciated. Thanks!
3DTOPO
 
Posts: 22
Joined: Sat May 01, 2010 3:21 am

Re: WiShield 2.0 Flash (non-WiFi) Sample

Postby spidermonkey04 » Tue Jun 22, 2010 9:04 pm

Did you add that extra DF_CS_Inactive() to the beginning of read_Id() ?
spidermonkey04
 
Posts: 66
Joined: Thu Oct 29, 2009 6:45 pm

Re: WiShield 2.0 Flash (non-WiFi) Sample

Postby 3DTOPO » Tue Jun 22, 2010 10:09 pm

I *think* so, here is what I have:

Code: Select all
void Dataflash::read_id (unsigned char* data)
{
  DF_CS_inactive();
  DF_CS_active();
  DF_SPI_RW(0x9F);   //read mfg id op-code
  data[0] = DF_SPI_RW(0x00);
  data[1] = DF_SPI_RW(0x00);
  data[2] = DF_SPI_RW(0x00);
  data[3] = DF_SPI_RW(0x00);
  DF_CS_inactive();
}


Thanks for your help Spidermonkey04!
3DTOPO
 
Posts: 22
Joined: Sat May 01, 2010 3:21 am

Re: WiShield 2.0 Flash (non-WiFi) Sample

Postby michelpereira » Wed Jun 30, 2010 7:38 am

Hi, I got the example above and I see a lot of strange things.
The first iteraction goes right, so the next I see only weird data. Am I doing something wrong?


---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---
Mfg ID: 1F
Dev ID: 260
---=== Flash Data byte/str contents ===---
byte: 160
str : Iteration: 160
---=== Updating Flash Data ===---

---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---
Mfg ID: FF
Dev ID: FFFF
---=== Flash Data byte/str contents ===---
byte: 0
str : Iteration: 0
---=== Updating Flash Data ===---

---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---
Mfg ID: FF
Dev ID: FFFF
---=== Flash Data byte/str contents ===---
byte: 1
str : Iteration: 1
---=== Updating Flash Data ===---

---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---
Mfg ID: FF
Dev ID: FFFF
---=== Flash Data byte/str contents ===---
byte: 2
str : Iteration: 2
---=== Updating Flash Data ===---

---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---
Mfg ID: FF
Dev ID: FFFF
---=== Flash Data byte/str contents ===---
byte: 3
str : Iteration: 3
---=== Updating Flash Data ===---

---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---
Mfg ID: FF
Dev ID: FFFF
---=== Flash Data byte/str contents ===---
byte: 4
str : Iteration: 4
---=== Updating Flash Data ===---

---=== Flash Mfg/Dev ID Data (should be 1F 26 0) ===---
Mfg ID: FF
Dev ID: FFFF
---=== Flash Data byte/str contents ===---
byte: 5
str : Iteration: 5
---=== Updating Flash Data ===---
michelpereira
 
Posts: 2
Joined: Wed Jun 30, 2010 7:15 am

Re: WiShield 2.0 Flash (non-WiFi) Sample

Postby GregEigsti » Wed Jun 30, 2010 9:47 am

It looks like just the Mfg/Dev IDs are coming back incorrectly? Search out spidermonkey04's posts - he has done a lot of work with the flash chip and may have worked around this.

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: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website


Return to WiShield 2.0

Who is online

Users browsing this forum: No registered users and 1 guest