Skip to content

Commit

Permalink
drivers: sensor: shtcx: fix val2 calculation
Browse files Browse the repository at this point in the history
The calculation of the sensor val2 did not correctly take the sign into
account.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
  • Loading branch information
str4t0m authored and nashif committed Jun 15, 2023
1 parent ecf2cb5 commit c9f8b8b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/sensor/shtcx/shtcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void shtcx_temperature_from_raw(uint16_t raw, struct sensor_value *val)
tmp = (int32_t)raw * 175U - (45 << 16);
val->val1 = tmp / 0x10000;
/* x * 1.000.000 / 65.536 == x * 15625 / 2^10 */
val->val2 = ((tmp % 0x10000) * 15625U) / 1024;
val->val2 = ((tmp % 0x10000) * 15625) / 1024;
}

/* val = 100 * sample / (2^16) */
Expand Down

0 comments on commit c9f8b8b

Please sign in to comment.