-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Description
I created a custom application for my custom board that used a NRF52840 at its core and is basically just the code of the samples/sensor/sgp40_sht4x sample to read the Sensor data. First I had some issue where the initialization "Failed to reset the device". I was able to fix this by enabling the internal pull-ups for the I2C Interface. Not sure why this was necessary since there are 4.7k Pull-up on the board, but if it works I am not complaining. After that I had troubles reading from the device as can be seen in the image below

I went to debug this and found that after setting a break point after the sht4x_write_command function call and before sht4x_read_sample in the sht4x.c file that I get correct readings on my Uart-Output.
After that I did some digging in the Datasheet (https://sensirion.com/resource/datasheet/sht4x) that there is a delay of 10ms between writing and reading via the I2C Interface. In the current implementation the delay is defined by the array measure_wait_us inside of the sht4.h file
static const uint16_t measure_wait_us[3] = { 1700, 4500, 8200 };
This corresponds to the "Measurement Duration" in the datasheet
, although some values are slightly different (probably Datasheet changes).
For testing I just set them all to 10000 (which will be a 10ms delay) and voila after that I can read the sensor without any errors.
Since I also verified before that my Board and the Sensor were working by using Arduino and PlatformIO. I check the implementation (https://github.com/Sensirion/arduino-i2c-sht4x/blob/master/src/SensirionI2cSht4x.cpp) there and found that they use slightly longer delays of 2ms,5ms,10ms.
I tested them aswell by changing the values from above to the following:
static const uint16_t measure_wait_us[3] = { 2000,5000, 10000 };
After testing all three repeatability settings, I can say that they all worked for me.

I suspect that the "Measurement Duration" form the Datasheet is the time needed for the measurement without the time needed to write them to the registers. At least that would explain why adding some additional time is working.
Maybe someone else can confirm this behaviour on there end as well? I can also do a PR if this is wanted.
Kind Regards