Page last edited May 22, 2014
Text editor powered by tinymce.
Page last edited May 22, 2014
Text editor powered by tinymce.
All pins are 3-5V compliant and use whatever logic level is on VCC
Page last edited May 22, 2014
Text editor powered by tinymce.
Page last edited May 22, 2014
Text editor powered by tinymce.
You can easily wire this breakout to any microcontroller, we'll be using a Metro
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
The library we have is simple and easy to use
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.
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)
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
uint8_t getStatusRegister();
setStatusRegister(uint8_t value);
Page last edited May 22, 2014
Text editor powered by tinymce.
It's easy to use the SPI FRAM Breakout with Python or CircuitPython and the Adafruit CircuitPython FRAM module. This module allows you to easily write Python code that reads the humidity, temperature, pressure, and more from the sensor.
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:
If you'd like to use the hardware write protection, connect another GPIO to the sensor's WP pad, like so:
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:
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.
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)
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)
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.
fram = adafruit_fram.FRAM_SPI(spi, cs, max_size = 524288)
fram = adafruit_fram.FRAM_SPI(spi, cs, max_size = 524288)
Now you can write or read to any address locations:
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 SPI FRAM Library import board import busio import digitalio import adafruit_fram ## Create a FRAM object. spi = busio.SPI(board.SCK, board.MOSI, board.MISO) cs = digitalio.DigitalInOut(board.D5) fram = adafruit_fram.FRAM_SPI(spi, cs) ## Write a single-byte value to register address '0' fram[0] = 1 ## Read that byte to ensure a proper write. ## Note: 'read()' returns a bytearray print(fram[0]) ## Or write a sequential value, then read the values back. ## Note: 'read()' returns a bytearray. It also allocates ## a buffer the size of 'length', which may cause ## problems on memory-constrained platforms. # values = list(range(100)) # or bytearray or tuple # fram[0:100] = values # print(fram[0:100])
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT ## Simple Example For CircuitPython/Python SPI FRAM Library import board import busio import digitalio import adafruit_fram ## Create a FRAM object. spi = busio.SPI(board.SCK, board.MOSI, board.MISO) cs = digitalio.DigitalInOut(board.D5) fram = adafruit_fram.FRAM_SPI(spi, cs) ## Write a single-byte value to register address '0' fram[0] = 1 ## Read that byte to ensure a proper write. ## Note: 'read()' returns a bytearray print(fram[0]) ## Or write a sequential value, then read the values back. ## Note: 'read()' returns a bytearray. It also allocates ## a buffer the size of 'length', which may cause ## problems on memory-constrained platforms. # values = list(range(100)) # or bytearray or tuple # fram[0:100] = values # print(fram[0:100])
Page last edited May 22, 2014
Text editor powered by tinymce.
Page last edited May 22, 2014
Text editor powered by tinymce.