Pinouts
The FRAM chip is the little guy in the middle. On the bottom we have the power and interface pins
Power Pins:
- VCC - this is the power pin. Since the chip uses 3-5VDC you should pick whatever the logic voltage you're using. For most Arduino's that's 5V.
- GND - common ground for power and logic
I2C Logic pins:
- WP - Write Protect pin. This is used to force write protection so you cannot write to the FRAM. It has an internal pulldown. Bring to a high voltage (VCC) to turn on WP.
- SCL - I2C clock pin, connect to your microcontroller's I2C clock line.
- SDA - I2C data pin, connect to your microcontroller's I2C data line.
- A2, A1, A0 - These are the I2C address selection pins. By default the I2C address is 0x50. Connecting these pins to VCC and power cycling the chip will adjust the lower three bits of the address. For example, if A0 is high, the address is 0x51. If A1 and A2 are high, the address is 0x56.
Assembly
Prepare the header strip:
Cut the strip to length if necessary. It will be easier to solder if you insert it into a breadboard - long pins downAdd the breakout board:
Place the breakout board over the pins so that the short pins poke through the breakout padsAnd Solder!
Be sure to solder all pins for reliable electrical contact.(For tips on soldering, be sure to check out our Guide to Excellent Soldering).
Arduino Test
-
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 SCL pin to the I2C clock SCL pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
- Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2
Download Adafruit_FRAM_I2C
To begin reading and writing data to the chip, you will need to download Adafruit_FRAM_I2C from our github repository. You can do that by visiting the github repo and manually downloading or, easier, just click this button to download the zipPlace the Adafruit_FRAM_I2C 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_I2C->MB85RC256V and upload to your Arduino wired up to the sensorThe 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 256KB!)
Library Reference
The library we have is simple and easy to useYou can create the FRAM object with
Adafruit_FRAM_I2C fram = Adafruit_FRAM_I2C();Then when you begin(), pass in the i2c address. The default is 0x50 so if you don't put any value in the default is used.
If you have different addresses, call something like
fram.begin(0x53)for example.
Then to write a value, call
fram.write8(address, byte-value);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.
CircuitPython
It's easy to use the I2C FRAM Breakout with CircuitPython and the Adafruit CircuitPython FRAM library.
CircuitPython Microcontroller Wiring
First we'll wire up the I2C FRAM Breakout to a microcontroller, as was shown in the Arduino Test page.
Here is an example of wiring the breakout to a Feather M0 Basic:
If you'd like to use the hardware write protection, connect another GPIO to the sensor's WP pad, like so:
- Board 3V to sensor VIN
- Board GND to sensor GND
- Board SDA to sensor SDA
- Board SCL to sensor SCL
- Board D5 to sensor WP
CircuitPython Installation of FRAM Library
You'll need to install the Adafruit CircuitPython FRAM library on your CircuitPython board.
First make sure you are running the latest version of Adafruit CircuitPython for your board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle. Our CircuitPython starter guide has a great page on how to install the library bundle.
For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:
- adafruit_fram.mpy
- adafruit_bus_device
Before continuing make sure your board's lib folder or root filesystem has the adafruit_fram.mpy, and adafruit_bus_device files and folders copied over.
Next connect to the board's serial REPL so you are at the CircuitPython >>>
prompt.
CircuitPython Usage
To demonstrate the usage of the breakout we'll initialize it, write data to the FRAM, and read that data from the board's Python REPL.
Run the following code to import the necessary modules and initialize the SPI connection with the breakout:
import board import digitalio import adafruit_fram i2c = board.I2C() fram = adafruit_fram.FRAM_I2C(i2c)
Or, if you're using the hardware write protection:
import board import digitalio import adafruit_fram i2c = board.I2C() wp = digitalio.DigitalInOut(board.D6) fram = adafruit_fram.FRAM_I2C(i2c, wp_pin=wp)
Now you can write or read to any address locations:
fram[0] = 1 fram[0]
Reading the FRAM returns a bytearray. To get a "raw" value, use the index of the value's location. Some various ways to get values are as such:
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT ## Simple Example For CircuitPython/Python I2C FRAM Library import board import busio import adafruit_fram ## Create a FRAM object (default address used). i2c = busio.I2C(board.SCL, board.SDA) fram = adafruit_fram.FRAM_I2C(i2c) ## Optional FRAM object with a different I2C address, as well ## as a pin to control the hardware write protection ('WP' ## pin on breakout). 'write_protected()' can be used ## independent of the hardware pin. # import digitalio # wp = digitalio.DigitalInOut(board.D10) # fram = adafruit_fram.FRAM_I2C(i2c, # address=0x53, # wp_pin=wp) ## Write a single-byte value to register address '0' fram[0] = 1 ## Read that byte to ensure a proper write. ## Note: reads return a bytearray print(fram[0]) ## Or write a sequential value, then read the values back. ## Note: reads return a bytearray. Reads also allocate ## a buffer the size of slice, which may cause ## problems on memory-constrained platforms. # values = list(range(100)) # or bytearray or tuple # fram[0:100] = values # print(fram[0:100])
Downloads
This guide was first published on May 20, 2014. It was last updated on May 20, 2014.