SPI Flash ics

SPI Flash chips are a fantastic way to store a medium amount of information for a microcontroller when you dont wish to impliment a whole filesystem layer. This is great for when you do not wish to use a large ram footprint (no large buffer needed!). They can provide relatively high density storage for a low cost, and enable high speed data storage.

This page will be updated in future, as my code progresses.. This is mainly just for small notes when working with Flash ICs

Communication

As per the name of the IC’s, these series of chips communicate using the SPI bus. I tend to only run them in single port mode, where there is a seperate data in and out pin. You can also run these chips in modes where the pins function similar to a paralell bus, this means that you can output more data per clock cycle and achieve higher data rates, however for most microcontroller projects it is not worth the extra code complexity to impliment these modes.

I use SPI in mode 0, and this has worked on all the chips i have used thus far, however checking the datasheet for the chip is always a good idea before beginning on the project.

Wiring

Connecting up the flash chip is as simple as connecting any other SPI connected chip, wire up the pins MOSI to MOSI etc. Note that most chips will have a physical write protect pin, this can be useful if the chip is not going to be programmed by your device, however i reccomend wiring to a GPIO just in case as it is a pain to have to re-spin a pcb or to include a bodge wire just for the one pin.

Protocol

The internal memory of the chip is structured into 512 byte pages, and then larger sectors (32/64k is common). When working with the memory, you have to be careful about where you are writing as you can only write to a single page (it is a new command to write to the next page). For my work with datalogging to the flash memory the easiest method is to make your data structure divide evenly into the 512 byte page OR have some left over space at the end of the page…

That said, it is still quite doable to work with the datastructure spanning over the pages, just extra logic to impliment.

Logic flow

When working with the memory, the main logic flow is quite simple:

Writing

  • send the write enable command
  • Send the write bytes command
  • Send the address
  • Send the data bytes

Reading

  • Send the read command
  • Send the addres
  • Read Bytes

The actual commands used will vary sometimes by the chip used, however the basic commands appear to be fairly standardised (along with the ic footprint)