Skip to content

Commit d999cbc

Browse files
Koepelabrauchli
authored andcommitted
Don't wait after Wire.requestFrom()
* Remove MAX_I2C_READ_TRIES
1 parent d2a380b commit d999cbc

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

SHTSensor.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ bool SHTSensorDriver::readSample()
5353

5454
const uint8_t SHTI2cSensor::CMD_SIZE = 2;
5555
const uint8_t SHTI2cSensor::EXPECTED_DATA_SIZE = 6;
56-
const uint8_t SHTI2cSensor::MAX_I2C_READ_TRIES = 5;
5756

5857
bool SHTI2cSensor::readFromI2c(uint8_t i2cAddress,
5958
const uint8_t *i2cCommand,
@@ -73,14 +72,9 @@ bool SHTI2cSensor::readFromI2c(uint8_t i2cAddress,
7372

7473
Wire.requestFrom(i2cAddress, dataLength);
7574

76-
// there should be no reason for this to not be ready, since we're using clock
77-
// stretching mode, but just in case we'll try a few times
78-
uint8_t tries = 1;
79-
while (Wire.available() < dataLength) {
80-
delay(1);
81-
if (tries++ >= MAX_I2C_READ_TRIES) {
82-
return false;
83-
}
75+
// check if the same number of bytes are received that are requested.
76+
if (Wire.available() != dataLength) {
77+
return false;
8478
}
8579

8680
for (int i = 0; i < dataLength; ++i) {

SHTSensor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ class SHTI2cSensor : public SHTSensorDriver {
226226
float mY;
227227

228228
private:
229-
static const uint8_t MAX_I2C_READ_TRIES;
230229
static uint8_t crc8(const uint8_t *data, uint8_t len);
231230
static bool readFromI2c(uint8_t i2cAddress,
232231
const uint8_t *i2cCommand,

0 commit comments

Comments
 (0)