From 3af9cee9ad25ca077b1d0e4f3dfebdb0f72a53f8 Mon Sep 17 00:00:00 2001 From: peteGSX <97784652+peteGSX@users.noreply.github.com> Date: Wed, 17 Jan 2024 12:40:24 +1000 Subject: [PATCH] Update while() --- I2CManager_Wire.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/I2CManager_Wire.h b/I2CManager_Wire.h index 1af1a68..d8add75 100644 --- a/I2CManager_Wire.h +++ b/I2CManager_Wire.h @@ -192,7 +192,11 @@ uint8_t I2CManagerClass::read(I2CAddress address, uint8_t readBuffer[], uint8_t DIAG(F("Wire.available()=%d"),Wire.available()); // while (Wire.available() && nBytes < readSize) while (nBytes < readSize) - readBuffer[nBytes++] = Wire.read(); + if (Wire.available()) { + readBuffer[nBytes++] = Wire.read(); + } else { + delay(1); + } // DIAG(F("nBytes=%d,readBuffer[nBytes]=%d"),nBytes-1,readBuffer[nBytes-1]); if (nBytes < readSize) status = I2C_STATUS_TRUNCATED; DIAG(F("status=%d"),status);