UncleRus / esp-idf-lib

Component library for ESP32-xx and ESP8266
https://esp-idf-lib.readthedocs.io/en/latest/
1.33k stars 414 forks source link

sht4x - Fix sporadic measurement errors by applying TIME_TO_TICKS() m… #632

Closed cmorganBE closed 1 month ago

cmorganBE commented 1 month ago

…acro from SHT3x driver to ensure the delay time is at least 1 more tick than desired

Replace pdMS_TO_TICKS() with TIME_TO_TICKS().

FreeRTOS vTaskDelay() (https://www.freertos.org/a00127.html) does NOT guarantee that the delay time is at least the ticks specified, relative to time.

The SHT4x has timing constraints that are required to be followed for the part to be ready to respond. In the case where the delay was 10ms and the FreeRTOS tick time is 10ms vTaskDelay(1) was being called. Measurement via oscilloscope confirmed that most of the time the delay was 10ms + 2-5ms, but sometimes it was 6ms or 7ms.

In the cases where the delay was <10ms, the SHT4x would not respond to the 'read measurement' phase of taking a measurement, resulting in i2cdev logging an error, and the measurement call failing.

UncleRus commented 1 month ago

Thank you!