Closed
Description
This may be a core bug but I'm starting here...
On a prototype board with MAX17048, I was consistently failing to initialize the device:
>>> s = adafruit_max1704x.MAX17048(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "adafruit_max1704x.py", line 115, in __init__
File "adafruit_max1704x.py", line 130, in reset
File "adafruit_register/i2c_bit.py", line 64, in __set__
OSError: [Errno 19] No such device
reset()
deliberately causes a transaction that will be NAK'd. However, on Adafruit CircuitPython 8.0.0-beta.4-25-g195ad4e479 on 2022-11-15; Adafruit Feather ESP32-S3 Reverse TFT with ESP32S3, the next I2C transaction after the NAK would also fail.
The following change seems to allow the module to consistently be initialized:
diff --git a/adafruit_max1704x.py b/adafruit_max1704x.py
index cb4d700..ae0eccd 100644
--- a/adafruit_max1704x.py
+++ b/adafruit_max1704x.py
@@ -120,11 +120,18 @@ class MAX17048:
try:
self._cmd = 0x5400
except OSError:
+ print("nak'd command")
# aha! we NACKed, which is CORRECT!
pass
else:
raise RuntimeError("Reset did not succeed")
- self.reset_alert = False # clean up RI alert
+ for _ in range(3):
+ print("trying to reset alert")
+ try:
+ self.reset_alert = False # clean up RI alert
+ return
+ except OSError as e:
+ print(f"tried to reset alert: {repr(e)}")
@property
def cell_voltage(self) -> float:
The debug prints that remain say that the first reset_alert
is also failed / NAK'd but the 2nd succeeds
s = adafruit_max1704x.MAX17048(b); time.sleep(.1); s.cell_voltage
nak'd command
trying to reset alert
tried to reset alert: OSError(19,)
trying to reset alert
4.2175
I did not scope the I2C bus to see whether the first attempted transaction to reset_alert
actually occurs or not.
Metadata
Metadata
Assignees
Labels
No labels