Shop Learn
SPI FRAM memory expansion — Parallax Forums

SPI FRAM memory expansion

UnsoundcodeUnsoundcode Posts: 1,450
edited 2022-05-10 17:54 in micro:bit

FRAM is non volatile memory that is fast to read and write and very simple to use. FRAM can be used for data logging, sound and image storage, small RFID databases and many more similar applications. I am giving here an example of the microbit interfaced to a Fujitsu FRAM module that uses the SPI protocol and is mounted on a breakout board sold by Adafruit.

Below is the beginnings of a small module, I have not included much in the way of documentation but will try to answer any questions if anyone has them. The code will work with the V1 and the V2 microbits. One important note is that the module is designed for the 2 Mbit or 4 Mbit Adafruit breakout boards which require a 24 bit address, if you want the same code to run with a 64 Kbit breakout it would need to be modified to use a 16 bit address which is no big deal.

The example not only demonstrates FRAM operations but is an example of creating a class module and the usage of spi in general, a 3 for 1 bonus. Multiple FRAM chips can be networked together to form a considerably large memory bank.

The module and it's methods:

The module name is

Add the module to the microbit on board file system.

The module accepts 2 arguments, a spi object and a pin which will be the chip select pin.

fram_id() returns the 4 byte ID for this particular brand of fram, the first byte will always be 0x4 which identifies the make of the chip as Fujitsu.

fram_wren() is the write enable method that must be issued before any write can be performed.

fram_read(address , byte_count) this method reads a number of bytes determined by the value in byte_count starting at the 24 bit value in address. The byte_count defaults to a value of 1.

fram_write(address, value) this method writes a byte value to the 24 bit address location. ****
Flash this to the microbit to test the module, it should return 4 bytes of information about the attached FRAM, my test returns 0x4, 0x7f, 0x48, 0x3

EDIT : replaced original module file because chip select was hard coded and I forgot to change it

Sign In or Register to comment.