enjoyneering / HTU21D

This is an Arduino library for HTU21D, Si7021 and SHT21 Digital Humidity & Temperature Sensor
55 stars 15 forks source link

The Wire.endTransmission() can not be called over and over again. #6

Closed Koepel closed 6 years ago

Koepel commented 6 years ago

When the Wire.endTransmission() is called in a while-loop, it could be called over and over again. The Wire.endTransmission() should not be called on its own. It is part of the: Wire.beginTransmission - Wire.Write - Wire.endTransmission.

At this moment, calling the Wire.endTransmission() once more might restart the complete I2C bus transaction. That is however not documented, and it might change in the future.

The Wire.requestFrom() is polled a number of times, until the same amount of bytes is received that was requested. I have seen that as well in the Sparkun library, but that is to poll the sensor until the data is ready. It is not to compensate for a bad I2C bus. Since you already have the appropriate delay, I suggest to call Wire.requestFrom() just once and return an error if it fails.

Koepel commented 6 years ago

This issue was my mistake. It is a do-while loop and not a while loop. The sensor itself is polled via I2C. Sorry for this mistake.