Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception handling for hexpansion I2C #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading