Today, for a project, I had to figure out how to use a Winbond Serial Flash Memory chip. It looked pretty simple at first: 16MB of memory , SPI interface, 3V3 level. But, it was my first time using an external Flash memory and of course I made a few mistakes along the way.All in all, it took me a few hours worth of playing around to figure out how to use it just right.
Here are the problems I ran into and their solutions:
1. Problem: Unreliable response to my command for requesting version( Send out 0×90, Receive two bytes with version info)
Solution: Immediately I realized this was a SPI system issue. Originally, I was on Mode 1 SPI( CPOL=0, CPHA=1) settings on my AVR microcontroller. Changing to Mode 0 SPI(CPOL=0, CPHA=0) or Mode 3 SPI (CPOL=1, CPHA=1) fixed this.
2. Problem: Overwriting data using the Program Page command didn’t work. For example, if I wrote 0×33, 0×34 , 0×35 originally and wanted to overwrite with 0×33, 0×45, 0×46 – I would read back 0×33, 0×00 , 0×00 . I would see zeros by any bytes that would be overwritten Bytes that were identical kept their value.
Solution: You have to clear that sector memory before you overwrite it. Programming only works when you are overwriting 0xFF(which is the value after a Sector Erase, Block Erase, or Chip Erase). Sector Erase is the smallest erase I’ve founded at 4k bytes erase so that means its also the quickest. Chip erase clears the entire chip ( duh) and it can take 30 seconds or more.