You can use the same wiring and test code for our older non-level-shifted breakout, or our newer versions which have a regulator and level shifting circuitry!

Arduino Wiring

You can easily wire this breakout to any microcontroller, we'll be using a Metro

  • Connect Vcc to the power supply, 3V or 5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
  • Connect GND to common power/data ground
  • Connect the SCK pin to the SPI clock pin on your Arduino. We'll be using Digital #13 which is also the hardware SPI pin on an Uno
  • Connect the MISO pin to the SPI MISO pin on your Arduino. We'll be using Digital #12 which is also the hardware SPI pin on an Uno.
  • Connect the MOSI pin to the SPI MOSI pin on your Arduino. We'll be using Digital #11 which is also the hardware SPI pin on an Uno.
  • Connect the CS pin to the SPI CS pin on your Arduino. We'll be using Digital #10 but any pin can be used later

Download Adafruit_FRAM_SPI

To begin reading and writing data, you will need to download Adafruit_FRAM_SPI from the Arduino Library Manager.

Open up the Arduino Library Manager: 

Search for the Adafruit FRAM SPI library and install it

Rename the uncompressed folder Adafruit_FRAM_SPI and check that the Adafruit_FRAM_SPI folder contains Adafruit_FRAM_SPI.cpp and Adafruit_FRAM_SPI.h

Place the Adafruit_FRAM_SPI library folder your arduinosketchfolder/libraries/ folder.
You may need to create the libraries subfolder if its your first library. Restart the IDE.

We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

Load Demo

Open up File->Examples->Adafruit_FRAM_SPI->MB85RS64V and upload to your Arduino wired up to the sensor
Thats it! Now open up the serial terminal window at 9600 speed to begin the test.

The test is fairly simple - It first verifies that the chip has been found. Then it reads the value written to location #0 in the memory, prints that out and write that value + 1 back to location #0. This acts like a restart-meter: every time the board is reset the value goes up one so you can keep track of how many times its been restarted.

Afterwards, the Arduino prints out the value in every location (all 8KB!)

Library Reference

The library we have is simple and easy to use

Hardware vs Software SPI

You can create the FRAM object using software-SPI (each pin can be any I/O) with

Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);

or use hardware SPI

Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS);

which means the other 3 pins are the hardware SPI defined pins for your chip. Check the SPI Reference page for details on which pins are which for your Arduino!

Hardware SPI is faster (the chip can handle up to 20MHz), but you have to use fixed pins. Software SPI is not as fast (maybe 1MHz max on an UNO), but you can switch pins around.

Begin


You can initialize the SPI interface and chip with begin()

fram.begin()

It will return true or false depending on whether a valid FRAM chip was found

For the 4Mbit version, you should change this to:

fram.begin(3)

 

Writing


Then to write a value, call

fram.writeEnable(true);
fram.write8(address, byte-value);

fram.writeEnable(false);

to write an 8-bit value to the address location
Later on of course you can also read with

fram.read8(address);

which returns a byte reading. For writing, you must enable writing before you send data to the chip, its for safety! However you can write as much as you want between the writeEnable calls

Block Protection

We dont cover how to protect subsections of the FRAM chip. It's covered a bit more inside the Datasheet.
For advanced users, we have two functions to set/get the Status Register. IF you want to set the status register dont forget that WP must be logical high!
uint8_t getStatusRegister();
setStatusRegister(uint8_t value);

This guide was first published on May 23, 2014. It was last updated on Mar 28, 2024.

This page (Arduino Test) was last updated on Mar 08, 2024.

Text editor powered by tinymce.