Close

FRAM Working

A project log for OURTicket

Open, Universal, Reliable Transport Ticketing.

BleckyBlecky 08/14/2014 at 02:110 Comments

Just a quick one. The FRAM works basically out of the box with the smbus library in python and the information in the datasheet.

#!/usr/bin/python

import smbus

bus = smbus.SMBus(1)    # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)

FRAM_ADDRESS = 0x50     #7 bit address without r/w bit (will be left shifted automatically)

bus.write_i2c_block_data(FRAM_ADDRESS, 0x00,[ 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 ]) #Write 0 - 7 from address 0
bus.write_i2c_block_data(FRAM_ADDRESS, 0x00, [0x00] )       #Set read position to 0 (address auto-increments each operation)
print bus.read_i2c_block_data(FRAM_ADDRESS, 0x00)           #Read from 0 and print

This should yield:

pi@ourticket-a ~ $ sudo python fram.py
[0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Discussions