From 1783b3da55902431198a295560cc4a473aa711ad Mon Sep 17 00:00:00 2001 From: Guillaume Gonnet Date: Thu, 16 May 2019 20:12:22 +0200 Subject: [PATCH] drivers/ds18: fix `ds18_read` with negative temperatures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When DS18 returns 0xFE6F (corresponding to -25.0625 °C), `ds18_read` returns 13877 whereas it should return -2506. This commit fixes this issue. --- drivers/ds18/ds18.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ds18/ds18.c b/drivers/ds18/ds18.c index 43b0d71b1d..f1ea75583f 100644 --- a/drivers/ds18/ds18.c +++ b/drivers/ds18/ds18.c @@ -184,7 +184,7 @@ int ds18_read(const ds18_t *dev, int16_t *temperature) 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); return DS18_OK;