# Adafruit SPI FRAM Breakouts

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/016/943/medium800/components_1897-00.jpg?1400859930)

You're probably familiar with SRAM, DRAM, EEPROM and Flash but what about FRAM? FRAM is 'ferroelectric' RAM, which has some very interesting and useful properties. Unlike SRAM, FRAM does not lose the data when power is lost. In that sense it's a durable storage memory chip like Flash. However, it is much faster than Flash - and you don't have to deal with writing or erasing pages.

![](https://cdn-learn.adafruit.com/assets/assets/000/016/944/medium800/components_1897-01.jpg?1400859939)

This particular FRAM chip has 64 Kbits (8 KBytes) of storage, interfaces using SPI, and can run at up to 20MHz SPI rates. Each byte can be read and written instantaneously (like SRAM) but will keep the memory for 95 years at room temperature. Each byte can be read/written 10,000,000,000,000 times so you don't have to worry too much about wear leveling.

![](https://cdn-learn.adafruit.com/assets/assets/000/016/945/medium800/components_1897-02.jpg?1400859945)

With the best of SRAM and Flash combined, this chip can let you buffer fairly-high speed data without worrying about data-loss.

# Adafruit SPI FRAM Breakouts

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/016/946/medium800/components_pinuot.jpg?1400859990)

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

## SPI Logic pins:

All pins are 3-5V compliant and use whatever logic level is on **VCC**

- **HOLD** - this is a 'wait' pin for the SPI bus. When pulled low, it puts the SPI bus on hold. This is different than the **CS** pin because it doesnt stop the current transaction. Its good if you want to talk to other SPI devices and stream data back and forth without stopping and starting transactions.
- **SCK** - This is the SPI clock pin, its an input to the chip
- **MISO** - this is the Microcontroller In Serial Out pin, for data sent from the FRAM to your processor
- **MOSI** - this is the Microcontroller Out Serial In pin, for data sent from your processor to the FRAM
- **CS** - this is the chip select pin, drop it low to start an SPI transaction. Its an input to the chip
- **WP** - Write Protect pin. This is used to write protect the **status register only**! This pin does not directly affect write protection for the entire chip. Instead, it protects the block-protect register which is configured however you want (sometimes only half the FRAM is protected)

# Adafruit SPI FRAM Breakouts

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/016/947/medium800/components_1897-01.jpg?1400860000)

 
## 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 down** ![components_header.jpg](https://cdn-learn.adafruit.com/assets/assets/000/016/933/medium640/components_header.jpg?1400786532)

## Add the breakout board:
Place the breakout board over the pins so that the short pins poke through the breakout pads![components_place.jpg](https://cdn-learn.adafruit.com/assets/assets/000/016/934/medium640/components_place.jpg?1400786552)

 
## And 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_](http://learn.adafruit.com/adafruit-guide-excellent-soldering)_)._![components_solder1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/016/935/medium640/components_solder1.jpg?1400786569)

![components_solder2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/016/936/medium640/components_solder2.jpg?1400786574)

![components_solder3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/016/937/medium640/components_solder3.jpg?1400786580)

You're done! Check your solder joints visually and continue onto the next steps

![components_done.jpg](https://cdn-learn.adafruit.com/assets/assets/000/016/938/medium640/components_done.jpg?1400786592)

# Adafruit SPI FRAM Breakouts

## Arduino Test

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/016/948/medium800/components_pinuot.jpg?1400860011)

# 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

![components_SPI_FRAM_Arduino_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/584/medium640/components_SPI_FRAM_Arduino_bb.jpg?1599244196)

![components_SPI_FRAM_original_Arduino_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/094/585/medium640/components_SPI_FRAM_original_Arduino_bb.jpg?1599244222)

# Download Adafruit\_FRAM\_SPI

To begin reading and writing data, you will need to [download Adafruit\_FRAM\_SPI&nbsp;](https://github.com/adafruit/Adafruit_FRAM_SPI "Link: https://github.com/adafruit/Adafruit\_FRAM\_SPI")from the Arduino Library Manager.

Open up the Arduino Library Manager:&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/088/324/medium800/components_1library_manager_menu.png?1581430078)

Search for the&nbsp; **Adafruit FRAM SPI&nbsp;** library and install it

![](https://cdn-learn.adafruit.com/assets/assets/000/088/326/medium800/components_fram_spi.png?1581430148)

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](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use "Link: 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 ![](https://cdn-learn.adafruit.com/assets/assets/000/016/939/medium800/components_example.gif?1448047131)

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!)

![](https://cdn-learn.adafruit.com/assets/assets/000/016/940/medium800/components_bytecount.png?1400786781)

# 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!](http://arduino.cc/en/Reference/SPI)  
  
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)**

&nbsp;

## 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);**

# Adafruit SPI FRAM Breakouts

## CircuitPython

Info: 

It's easy to use the SPI FRAM Breakout with Python or CircuitPython and the [Adafruit CircuitPython FRAM](https://github.com/adafruit/Adafruit_CircuitPython_FRAM) module.&nbsp; This module allows you to easily write Python code that reads the humidity, temperature, pressure, and more from the sensor.

# CircuitPython Microcontroller Wiring

First we'll wire up a SPI FRAM Breakout to a microcontroller.

Here is an example of wiring the breakout to a Feather M0 Basic or a Feather M4:

- **Board 3V** to **sensor VIN**
- **Board GND** to **sensor GND**
- **Board SCK** to **sensor SCK**
- **Board MOSI** to **sensor MOSI**
- **Board MISO** to **sensor MISO**
- **Board D5** to **sensor CS**

![components_SPI_FRAM_FeatherM4_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/098/879/medium640/components_SPI_FRAM_FeatherM4_bb.jpg?1611597631)

![components_SPI_FRAM_original_FeatherM0.png](https://cdn-learn.adafruit.com/assets/assets/000/098/880/medium640/components_SPI_FRAM_original_FeatherM0.png?1611597664)

If you'd like to use the hardware write protection, connect another GPIO to the sensor's&nbsp; **WP** pad, like so:

- **Board 3V** to **sensor VIN**
- **Board GND** to **sensor GND**
- **Board SCK** to **sensor SCK**
- **Board MOSI** to **sensor MOSI**
- **Board MISO** to **sensor MISO**
- **Board D5** to **sensor CS**
- **Board D6&nbsp;** to&nbsp; **sensor WP**

![components_SPI_FRAM_FeatherM4_write_protect_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/098/881/medium640/components_SPI_FRAM_FeatherM4_write_protect_bb.jpg?1611597693)

![components_SPI_FRAM_original_FeatherM0_write_protect.png](https://cdn-learn.adafruit.com/assets/assets/000/098/882/medium640/components_SPI_FRAM_original_FeatherM0_write_protect.png?1611597708)

Info: 

# CircuitPython Installation of FRAM Library

You'll need to install the&nbsp;[Adafruit CircuitPython FRAM](https://github.com/adafruit/Adafruit_CircuitPython_FRAM)&nbsp;library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

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&nbsp; **adafruit\_fram.mpy,** and **adafruit\_bus\_device**** &nbsp; **files and folders** &nbsp;**copied over.

Next[&nbsp;connect to the board's serial REPL](https://learn.adafruit.com/welcome-to-circuitpython/the-repl) so you are at the CircuitPython&nbsp;`>>>`&nbsp;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 busio
import digitalio
import adafruit_fram
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = digitalio.DigitalInOut(board.D5)
fram = adafruit_fram.FRAM_SPI(spi, cs)
```

Or, if you're using the hardware write protection:

```
import board
import busio
import digitalio
import adafruit_fram
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = digitalio.DigitalInOut(board.D5)
wp = digitalio.DigitalInOut(board.D6)
fram = adafruit_fram.FRAM_SPI(spi, cs, wp_pin=wp)
```

The default address space is 8 KByte for the smallest FRAM device. If you are using a larger FRAM device like the 4Mbit / 512 KByte use **max\_size** during constructor initialization.

```auto
fram = adafruit_fram.FRAM_SPI(spi, cs, max_size = 524288)
```

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:

![](https://cdn-learn.adafruit.com/assets/assets/000/067/115/medium800/components_fram_repl_read.png?1544070390)

# Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_FRAM/blob/main/examples/fram_spi_simpletest.py

# Adafruit SPI FRAM Breakouts

## Python Docs

# Adafruit SPI FRAM Breakouts

## Downloads

# Datasheets & Files

- [MB85RS64V Datasheet](http://www.adafruit.com/datasheets/MB85RS64V-DS501-00015-4v0-E.pdf)
- [Fritzing object in Adafruit Fritzing library](https://github.com/adafruit/Fritzing-Library)
- [EagleCAD PCB files](https://github.com/adafruit/Adafruit-FRAM-Breakout-PCB)

# Schematics
![](https://cdn-learn.adafruit.com/assets/assets/000/016/941/medium800/components_schem.png?1400787494)

# Fabrication Print
![](https://cdn-learn.adafruit.com/assets/assets/000/016/942/medium800/components_fabprintfront.png?1400787564)


## Featured Products

### Adafruit SPI Non-Volatile FRAM Breakout - 64Kbit / 8KByte

[Adafruit SPI Non-Volatile FRAM Breakout - 64Kbit / 8KByte](https://www.adafruit.com/product/1897)
FRAM, or [Ferroelectric Ram,](http://en.wikipedia.org/wiki/Ferroelectric_RAM) is the coolest new data storage method that all the fashion magazines are talking about. Oh wait, no that's quilted handbags. But FRAM is pretty damn cool too! It's similar to <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1897)
[Related Guides to the Product](https://learn.adafruit.com/products/1897/guides)

## Related Guides

- [Adafruit MagTag](https://learn.adafruit.com/adafruit-magtag.md)
- [MASLOW: an Open WiFi Detector with Adafruit Pro Trinket and CC3000](https://learn.adafruit.com/wifi-hotspot-finder-adafruit-pro-trinket-cc3000.md)
- [Adafruit QT 3V to 5V Level Booster Breakout](https://learn.adafruit.com/adafruit-qt-3v-to-5v-level-booster-breakout.md)
- [Adafruit NeoPixel Driver BFF](https://learn.adafruit.com/adafruit-neopixel-driver-bff.md)
- [Adafruit DotStar FeatherWing](https://learn.adafruit.com/adafruit-dotstar-featherwing-adafruit.md)
- [Adafruit 1.9" Color IPS TFT Display](https://learn.adafruit.com/adafruit-1-9-color-ips-tft-display.md)
- [Adafruit SPI FRAM Breakout - 2 or 4 Mbit](https://learn.adafruit.com/spi-fram-2mbit-4mbit.md)
- [Adafruit PiOLED - 128x32 Mini OLED for Raspberry Pi](https://learn.adafruit.com/adafruit-pioled-128x32-mini-oled-for-raspberry-pi.md)
- [IoT Bird Feeder with Camera](https://learn.adafruit.com/iot-window-bird-feeder-with-camera.md)
- [2.7" Monochrome 128x64 OLED Display Module](https://learn.adafruit.com/2-7-monochrome-128x64-oled-display-module.md)
- [Adafruit DPI Display Kippah](https://learn.adafruit.com/adafruit-dpi-display-kippah-ttl-tft.md)
- [Adafruit MCP23017 I2C GPIO Expander](https://learn.adafruit.com/adafruit-mcp23017-i2c-gpio-expander.md)
- [Adafruit Feather M0 Adalogger](https://learn.adafruit.com/adafruit-feather-m0-adalogger.md)
- [Adafruit SEN6x Breakout](https://learn.adafruit.com/adafruit-sen6x-breakout.md)
- [Adafruit IoT Button with NeoPixel BFF](https://learn.adafruit.com/adafruit-iot-button-with-neopixel-bff.md)
