drivers/ds18: fix ds18_read with negative temperatures
When DS18 returns 0xFE6F (corresponding to -25.0625 °C), `ds18_read` returns 13877 whereas it should return -2506. This commit fixes this issue.
This commit is contained in:
parent
901513391a
commit
1783b3da55
@ -184,7 +184,7 @@ int ds18_read(const ds18_t *dev, int16_t *temperature)
|
|||||||
|
|
||||||
DEBUG("[DS18] Received byte: 0x%02x\n", b2);
|
DEBUG("[DS18] Received byte: 0x%02x\n", b2);
|
||||||
|
|
||||||
int32_t measurement = ((int32_t)(b2 << 8 | b1) * 625);
|
int32_t measurement = ((int16_t)(b2 << 8 | b1) * 625);
|
||||||
*temperature = (int16_t)(measurement / 100);
|
*temperature = (int16_t)(measurement / 100);
|
||||||
|
|
||||||
return DS18_OK;
|
return DS18_OK;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user