Exemplo n.º 1
0
## 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] = values
# print(fram[0:99])
import digitalio
import time
import adafruit_fram

# Create SPI Bus
spi_bus = busio.SPI(board.SCK, board.MOSI, board.MISO)

# Set Up Chip-Select
spi_cs = digitalio.DigitalInOut(board.D2)
spi_cs.direction = digitalio.Direction.OUTPUT
spi_cs.value = True

# Set Up SPI FRAM
fram = adafruit_fram.FRAM_SPI(spi_bus,
                              spi_cs,
                              write_protect=False,
                              wp_pin=None,
                              baudrate=12000000)  # 12MHz

byteArrayRange = len(fram)  # 8192 Bytes


def spiFramReset(startAddress, resetLength):
    if ((startAddress < 0) or (startAddress > 8191)):
        print("-> ERROR: startAddress must be between 0 and {}.".format(
            byteArrayRange - 1),
              end="")
    else:
        if (resetLength > byteArrayRange):
            print(
                "-> ERROR: Can't reset more than the space on the FRAM Chip, which is 8192 bytes...",