Skip to content

Commit 146968f

Browse files
committed
enh: added scan i2c address space
1 parent 9783016 commit 146968f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

basil/HL/i2c.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,24 @@ def read(self, addr, size):
124124
pass
125125

126126
return self.get_data(size)
127+
128+
def scan_i2c_address(self) -> list:
129+
"""Scans the whole i2c address space by writing an empty command to each address,
130+
and checking if a acknowledge flag is set.
131+
Note: basil uses an additional [R/W] bit for addressing compared to the I2C hardware address.
132+
133+
Returns:
134+
list: List of all found I2C address
135+
"""
136+
addr = []
137+
for address in range(0x80):
138+
try:
139+
self.write(address << 1, [0])
140+
# Basil uses the additional [R/W] bit for addressing
141+
print("Found I2C at basil address: ", hex(address << 1))
142+
print("Corresponding to I2C address: ", hex(address), ",", bin(address))
143+
print("-----------------------------------------------")
144+
addr.append(bin(address))
145+
except OSError:
146+
pass
147+
return addr

0 commit comments

Comments
 (0)