SPI FRAM Reading And Writing
We highly encourage everyone to use our new Python package which is packed with features. This library is still supported, but is not recommended for new design.
This example is a very brief demonstration of using SPI to read from and write to a SPI FRAM device. This particular examples uses the 64Kbit FRAM Breakout Board from Adafruit.
1
from binhoHostAdapter import binhoHostAdapter
2
from binhoHostAdapter import binhoUtilities
3
4
# Change this to match your COMPort
5
default_commport = "COM11"
6
7
print("SPI FRAM Example using Binho Host Adapter")
8
print("v1.0 -- Jonathan Georgino <[email protected]>")
9
print
10
11
utilities = binhoUtilities.binhoUtilities()
12
devices = utilities.listAvailableDevices()
13
14
if len(devices) == 1:
15
COMPORT = devices[0]
16
print("Found 1 attached adapter @ " + devices[0])
17
print
18
else:
19
COMPORT = default_commport
20
print("Found more than 1 attached adapter, using default port " + COMPORT)
21
print
22
23
print("Opening " + COMPORT + "...")
24
print
25
26
# create the binhoHostAdapter object
27
hostAdapter = binhoHostAdapter.binhoHostAdapter(COMPORT)
28
29
print(hostAdapter.setOperationMode(0, 'SPI'))
30
print(hostAdapter.setClockSPI(0, 1000000))
31
print(hostAdapter.setModeSPI(0, 0))
32
print(hostAdapter.setIOpinMode(0, 'DOUT'))
33
print(hostAdapter.setIOpinValue(0, 'HIGH'))
34
35
print(hostAdapter.beginSPI(0))
36
print(hostAdapter.setIOpinValue(0, 'LOW'))
37
38
print(hostAdapter.transferSPI(0, 0x9f))
39
print(hostAdapter.transferSPI(0, 0))
40
print(hostAdapter.transferSPI(0, 0))
41
print(hostAdapter.transferSPI(0, 0))
42
print(hostAdapter.transferSPI(0, 0))
43
44
print(hostAdapter.setIOpinValue(0, 'HIGH'))
45
print(hostAdapter.endSPI(0))
46
47
48
print(hostAdapter.clearBuffer(0))
49
print(hostAdapter.addByteToBuffer(0, 0x9f))
50
51
print(hostAdapter.beginSPI(0))
52
print(hostAdapter.setIOpinValue(0, 'LOW'))
53
54
print(hostAdapter.transferBufferSPI(0, 5))
55
56
print(hostAdapter.setIOpinValue(0, 'HIGH'))
57
print(hostAdapter.endSPI(0))
58
59
print(hostAdapter.readBuffer(0, 5))
Copied!
Last modified 8mo ago
Copy link