From 5fcdffc8c036a05a51484de90323524ea08e4bfa Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 20 Apr 2022 16:06:28 -0400 Subject: [PATCH] drivers/device/nuttx/I2C: only issue I2C_RESET() if retrying, and only before the next retry --- src/lib/drivers/device/nuttx/I2C.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/drivers/device/nuttx/I2C.cpp b/src/lib/drivers/device/nuttx/I2C.cpp index b7054b3d36..ed4a377c5d 100644 --- a/src/lib/drivers/device/nuttx/I2C.cpp +++ b/src/lib/drivers/device/nuttx/I2C.cpp @@ -225,9 +225,11 @@ I2C::transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const break; } - /* if we have already retried once, or we are going to give up, then reset the bus */ - if ((retry_count >= 1) || (retry_count >= _retries)) { + // if we have already retried once, and we aren't going to give up, then reset the bus + if ((_retries > 0) && (retry_count < _retries)) { #if defined(CONFIG_I2C_RESET) + DEVICE_DEBUG("I2C bus: %d, Addr: %X, I2C_RESET %d/%d", + get_device_bus(), get_device_address(), retry_count + 1, _retries); I2C_RESET(_dev); #endif // CONFIG_I2C_RESET }