Ejemplo n.º 1
0
# 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
Ejemplo n.º 2
0
"""`frams`
FRAM stuff
"""
import board
import busio
import adafruit_fram
import struct

__version__ = "beta"

i2c = busio.I2C(board.SCL, board.SDA)
fram = adafruit_fram.FRAM_I2C(i2c, address=0x50)


# check if addresses are free to use
def checkfree(size, address):
    for i in range(size):
        if size < 4:
            return True
            break
        # check address is free
        if fram[address + i] != bytearray(b'\xff'):
            # show first address in use
            print('Address', (address + i), 'first to fail checkfree')
            print('Use "frams.erase({},'.format(size - i),
                  '{})""'.format(address + i))
            return False
            break
    print('Addresses needed are free to write.')
    return True