Skip to content

Commit

Permalink
exception handling for hexpansion I2C
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotmad committed Aug 20, 2024
1 parent c7ba4e4 commit 47f1334
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/lib/eeprom_i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,20 @@ def readwrite(self, addr, buf, read):
# Offset address into chip: one or two bytes
vaddr = self._addrbuf[1:] if self._onebyte else self._addrbuf
if read:
self._i2c.writeto(self._i2c_addr, vaddr)
self._i2c.readfrom_into(self._i2c_addr, mvb[start : start + npage])
try:
self._i2c.writeto(self._i2c_addr, vaddr)
self._i2c.readfrom_into(self._i2c_addr, mvb[start : start + npage])
except OSError:
# failure - possibly a hexpansion has been removed
nbytes = 0
else:
self._i2c.writevto(self._i2c_addr, (vaddr, buf[start : start + npage]))
try:
self._i2c.writevto(
self._i2c_addr, (vaddr, buf[start : start + npage])
)
except OSError:
# failure - possibly a hexpansion has been removed
nbytes = 0
self._wait_rdy()
nbytes -= npage
start += npage
Expand Down

0 comments on commit 47f1334

Please sign in to comment.