I2C Peripheral Mode
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 demonstrates how to use Binho Nova as an I2C Peripheral device, with a device address of 0xA0 and operating in USEPTR mode of emulation.
1
import os
2
import subprocess
3
import shutil
4
import psutil
5
import sys
6
7
from binhoHostAdapter import binhoHostAdapter
8
from binhoHostAdapter import binhoUtilities
9
10
from time import sleep
11
12
# enter the deviceID of target test device
13
binhoID = '0x1c4780b050515950362e3120ff141c2a'
14
15
utilities = binhoUtilities.binhoUtilities()
16
17
binhoComPorts = utilities.getPortByDeviceID(binhoID)
18
binhoComPort = 0
19
20
if len(binhoComPorts) == 0:
21
print("ERROR: No Binho Slave Device found!")
22
exit(1)
23
elif len(binhoComPorts) > 1:
24
print("ERROR: More than one Binho Slave Device found!")
25
exit(1)
26
else:
27
binhoComPort = binhoComPorts[0]
28
print("Found Binho Slave Device on " + binhoComPort)
29
30
31
print("Opening " + binhoComPort + "...")
32
print()
33
34
# create the binhoHostAdapter object
35
binhoNova = binhoHostAdapter.binhoHostAdapter(binhoComPort)
36
37
print("Configuring Binho Nova I2C Slave with address of 0xA0")
38
39
binhoNova.setLEDColor('RED')
40
binhoNova.setOperationMode(0, 'I2C')
41
binhoNova.setPullUpStateI2C(0, "EN")
42
43
# assign the address of 0xA0
44
binhoNova.setSlaveAddressI2C(0, 0xA0)
45
46
# set the mode to USEPTR mode
47
binhoNova.setSlaveModeI2C(0, "USEPTR")
48
49
# load some initial values into registers 0x06 - 0x11
50
binhoNova.setSlaveRegisterI2C(0,0x06,0x00)
51
binhoNova.setSlaveRegisterI2C(0,0x07,0x06)
52
binhoNova.setSlaveRegisterI2C(0,0x08,0x05)
53
binhoNova.setSlaveRegisterI2C(0,0x09,0x00)
54
binhoNova.setSlaveRegisterI2C(0,0x0A,0x04)
55
binhoNova.setSlaveRegisterI2C(0,0x0B,0x00)
56
binhoNova.setSlaveRegisterI2C(0,0x0C,0x00)
57
binhoNova.setSlaveRegisterI2C(0,0x0D,0x00)
58
binhoNova.setSlaveRegisterI2C(0,0x0E,0x00)
59
binhoNova.setSlaveRegisterI2C(0,0x0F,0x00)
60
binhoNova.setSlaveRegisterI2C(0,0x10,0x00)
61
binhoNova.setSlaveRegisterI2C(0,0x11,0xFF)
62
63
# make all the registers readonly by setting WriteMasks to 0x00
64
binhoNova.setSlaveWriteMaskI2C(0, 0x06, 0x00)
65
binhoNova.setSlaveWriteMaskI2C(0, 0x07, 0x00)
66
binhoNova.setSlaveWriteMaskI2C(0, 0x08, 0x00)
67
binhoNova.setSlaveWriteMaskI2C(0, 0x09, 0x00)
68
binhoNova.setSlaveWriteMaskI2C(0, 0x0A, 0x00)
69
binhoNova.setSlaveWriteMaskI2C(0, 0x0B, 0x00)
70
binhoNova.setSlaveWriteMaskI2C(0, 0x0C, 0x00)
71
binhoNova.setSlaveWriteMaskI2C(0, 0x0D, 0x00)
72
binhoNova.setSlaveWriteMaskI2C(0, 0x0E, 0x00)
73
binhoNova.setSlaveWriteMaskI2C(0, 0x0F, 0x00)
74
binhoNova.setSlaveWriteMaskI2C(0, 0x10, 0x00)
75
binhoNova.setSlaveWriteMaskI2C(0, 0x11, 0x00)
76
77
# set the Pointer register to 0x00
78
binhoNova.setSlaveWriteMaskI2C(0, 'PTR', 0x00)
79
print(binhoNova.getSlaveWriteMaskI2C(0, 'PTR'))
80
81
# read back the configuration and print it out
82
for i in range(12):
83
print(binhoNova.getSlaveRegisterI2C(0,6+i))
84
print(binhoNova.getSlaveWriteMaskI2C(0,6+i))
85
print()
86
87
print()
88
print("It's Over!")
89
binhoNova.close()
Copied!
Last modified 8mo ago
Copy link