aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorTimofey Titovets <nefelim4ag@gmail.com>2025-07-03 21:50:35 +0200
committerKevinOConnor <kevin@koconnor.net>2025-07-11 10:46:57 -0400
commit2585accfeb0e8291a0d428e8d3dfc72ff8f0cec7 (patch)
tree66aaace13f2f20baf2745e9f179637e7e21a7127 /klippy
parent37ddab223f54823d7252f87ea1b025a43031b878 (diff)
downloadkutter-2585accfeb0e8291a0d428e8d3dfc72ff8f0cec7.tar.gz
kutter-2585accfeb0e8291a0d428e8d3dfc72ff8f0cec7.tar.xz
kutter-2585accfeb0e8291a0d428e8d3dfc72ff8f0cec7.zip
sht3x: reads should be retried with at least 0.5s pause
SHT3x would return a read NACK on host retries. When the MCU receives the I2C CMD, it reads out data. SHT3x clears the data buffer. The MCU fails to deliver a response to the host. The host retries, the device returns NACK, then the MCU goes into the shutdown state. Make sure there is at least 0.5s between retries. Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/extras/bus.py4
-rw-r--r--klippy/extras/sht3x.py16
2 files changed, 17 insertions, 3 deletions
diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py
index c07ec826..4121c1c8 100644
--- a/klippy/extras/bus.py
+++ b/klippy/extras/bus.py
@@ -217,8 +217,8 @@ class MCU_I2C:
def i2c_write_wait_ack(self, data, minclock=0, reqclock=0):
self.i2c_write_cmd.send_wait_ack([self.oid, data],
minclock=minclock, reqclock=reqclock)
- def i2c_read(self, write, read_len):
- return self.i2c_read_cmd.send([self.oid, write, read_len])
+ def i2c_read(self, write, read_len, retry=True):
+ return self.i2c_read_cmd.send([self.oid, write, read_len], retry)
def MCU_I2C_from_config(config, default_addr=None, default_speed=100000):
# Load bus parameters
diff --git a/klippy/extras/sht3x.py b/klippy/extras/sht3x.py
index 5a8785e8..79cd7bfe 100644
--- a/klippy/extras/sht3x.py
+++ b/klippy/extras/sht3x.py
@@ -56,6 +56,7 @@ class SHT3X:
self.reactor = self.printer.get_reactor()
self.i2c = bus.MCU_I2C_from_config(
config, default_addr=SHT3X_I2C_ADDR, default_speed=100000)
+ self._error = self.i2c.get_mcu().error
self.report_time = config.getint('sht3x_report_time', 1, minval=1)
self.deviceId = config.get('sensor_type')
self.temp = self.min_temp = self.max_temp = self.humidity = 0.
@@ -105,7 +106,20 @@ class SHT3X:
def _sample_sht3x(self, eventtime):
try:
# Read measurment
- params = self.i2c.i2c_read(SHT3X_CMD['OTHER']['FETCH'], 6)
+ retries = 5
+ params = None
+ error = None
+ while retries > 0 and params is None:
+ try:
+ params = self.i2c.i2c_read(
+ SHT3X_CMD['OTHER']['FETCH'], 6, retry=False
+ )
+ except self._error as e:
+ error = e
+ self.reactor.pause(self.reactor.monotonic() + .5)
+ retries -= 1
+ if params is None:
+ raise error
response = bytearray(params['response'])
rtemp = response[0] << 8