Suppose to have a I2C device like Sensirion sht21, the datasheet says that the sensor supports both hold master read mode and no hold master read mode.

In addition to that, suppose that the library that reads the devices supports both reading mode.

And that in the I2C bus there is the only one sensor.

Using "long" distances (5/10m) I've seen that using no hold master mode, the MCU (ATMEGA328P) gave me many reading errors, switching to hold master mode, everything works as expected, no issues at all.

How, and why, using hold master mode I'm seeing that?

  • \$\begingroup\$ How did you implement the "no hold master" read? Do you wait for the conversion to be available, before reading it? Post the code for analysis. \$\endgroup\$
    – Justme
    Commented Aug 9, 2020 at 15:09
  • \$\begingroup\$ Here it's the library: github.com/e-radionicacom/SHT21-Arduino-Library \$\endgroup\$
    – VirtApp
    Commented Aug 9, 2020 at 15:19
  • \$\begingroup\$ What errors did you get? \$\endgroup\$
    – Justme
    Commented Aug 9, 2020 at 15:48
  • \$\begingroup\$ -6 or 127, that indicates wrong measurements \$\endgroup\$
    – VirtApp
    Commented Aug 9, 2020 at 16:12
  • \$\begingroup\$ Are those the data read back wrong, or the resulting error code some function returns? \$\endgroup\$
    – Justme
    Commented Aug 9, 2020 at 17:51

1 Answer 1


By looking at the SHT21 library code, and how it uses the underlying I2C bus with Arduino Wire library, the SHT21 code is not exactly compatible with "No Hold Master" reading if the result is tried to read back earlier than when it is ready.

When the temperature or humidity read is started, the SHT21 will not respond to it's I2C address until it is ready. The SHT21 library code starts I2C command to do a conversion, delays for approximately the time that it takes to perform the conversion, and then starts an I2C read only once and then waits for 3 bytes to be transferred. Since the I2C read failed already when SHT21 sensor does not acknowledge the address, there will never be any bytes transferred, so the code times out and returns with 0. This will happen if for some reason the delay is not long enough, and the sensor is still doing the conversion. The sequence should be so that if the sensor was not ready, the read should be started again.

The delay should be long enough as it is what the datasheet recommends, but perhaps there is something else that makes it spend more time doing the conversion or the delays are shorter than actually requested.

The reason why the "Hold Master" mode works, is that when the SHT21 sensor is performing a conversion, it will respond to the I2C read with an acknowledge, but pulls the I2C SCK pin low to make the host wait until conversion is ready. The Arduino Wire library can handle the clock stretching, and it does not have to wait that long, as the bulk delay has already been done separately after starting a conversion.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.