Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions components/sht4x/sht4x.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@

#define I2C_FREQ_HZ 1000000 // 1MHz

// due to the fact that ticks can be smaller than portTICK_PERIOD_MS, one and
// a half tick period added to the duration to be sure that waiting time for
// the results is long enough
#define TIME_TO_TICKS(ms) (1 + ((ms) + (portTICK_PERIOD_MS-1) + portTICK_PERIOD_MS/2 ) / portTICK_PERIOD_MS)

static const char *TAG = "sht4x";

#define CMD_RESET 0x94
Expand Down Expand Up @@ -225,7 +230,7 @@ esp_err_t sht4x_init(sht4x_t *dev)
dev->heater = SHT4X_HEATER_OFF;

sht4x_raw_data_t s;
CHECK(exec_cmd(dev, CMD_SERIAL, pdMS_TO_TICKS(10), s));
CHECK(exec_cmd(dev, CMD_SERIAL, TIME_TO_TICKS(10), s));
dev->serial = ((uint32_t)s[0] << 24) | ((uint32_t)s[1] << 16) | ((uint32_t)s[3] << 8) | s[4];

return sht4x_reset(dev);
Expand Down Expand Up @@ -273,7 +278,7 @@ size_t sht4x_get_measurement_duration(sht4x_t *dev)
{
if (!dev) return 0;

size_t res = pdMS_TO_TICKS(get_duration_ms(dev));
size_t res = TIME_TO_TICKS(get_duration_ms(dev));
return res == 0 ? 1 : res;
}

Expand Down
Loading