Skip to content

Commit 099669f

Browse files
committed
i2c scan logic change
I patched generic_linux/i2c.py:I2C.scan() to: • scan only 0x08..0x77 • try write_quick() first, fall back to read_byte()
1 parent 6a4f208 commit 099669f

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

  • src/adafruit_blinka/microcontroller/generic_linux

src/adafruit_blinka/microcontroller/generic_linux/i2c.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ def __init__(self, bus_num, mode=MASTER, baudrate=None):
4141
# pylint: enable=unused-argument
4242

4343
def scan(self):
44-
"""Try to read a byte from each address, if you get an OSError
45-
it means the device isnt there"""
44+
"""Probe each address; return those that ACK."""
4645
found = []
47-
for addr in range(0, 0x80):
46+
for addr in range(0x08, 0x78):
4847
try:
49-
self._i2c_bus.read_byte(addr)
48+
self._i2c_bus.write_quick(addr)
5049
except OSError:
51-
continue
50+
try:
51+
self._i2c_bus.read_byte(addr)
52+
except OSError:
53+
continue
5254
found.append(addr)
5355
return found
5456

0 commit comments

Comments
 (0)