Skip to content

Commit b8cc60e

Browse files
committed
bugfix(hts221): hts221 temperature data below 20 degrees is negative.
1 parent 8e51c41 commit b8cc60e

File tree

1 file changed

+3
-3
lines changed
  • components/i2c_devices/sensor/hts221

1 file changed

+3
-3
lines changed

components/i2c_devices/sensor/hts221/hts221.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ esp_err_t iot_hts221_get_temperature(hts221_handle_t sensor, int16_t *temperatur
355355
int16_t t0_out, t1_out, t_out, t0_degc_x8_u16, t1_degc_x8_u16;
356356
int16_t t0_degc, t1_degc;
357357
uint8_t buffer[4], tmp_8;
358-
uint32_t tmp_32;
358+
int32_t tmp_32;
359359
iot_hts221_read(sensor, HTS221_T0_DEGC_X8, 2, buffer);
360360
iot_hts221_read(sensor, HTS221_T0_T1_DEGC_H2, 1, &tmp_8);
361361
t0_degc_x8_u16 = (((uint16_t)(tmp_8 & 0x03)) << 8) | ((uint16_t)buffer[0]);
@@ -370,11 +370,11 @@ esp_err_t iot_hts221_get_temperature(hts221_handle_t sensor, int16_t *temperatur
370370
iot_hts221_read(sensor, HTS221_TEMP_OUT_L_REG, 2, buffer);
371371
t_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
372372

373-
tmp_32 = ((uint32_t)(t_out - t0_out)) * ((uint32_t)(t1_degc - t0_degc) * 10);
373+
tmp_32 = ((int32_t)(t_out - t0_out)) * ((int32_t)(t1_degc - t0_degc) * 10);
374374
if ((t1_out - t0_out) == 0) {
375375
return ESP_FAIL;
376376
}
377-
*temperature = tmp_32 / (t1_out - t0_out) + t0_degc * 10;
377+
*temperature = tmp_32 / (int32_t)(t1_out - t0_out) + t0_degc * 10;
378378
return ESP_OK;
379379
}
380380

0 commit comments

Comments
 (0)