From dc2c4be4e9e4f2c1ce7a177ba8c64c36624accdc Mon Sep 17 00:00:00 2001 From: darksv Date: Sun, 28 Feb 2016 11:30:16 +0100 Subject: [PATCH] Fix delay in DS18B20 driver There is a bug in the driver for DS18B20: instead of delaying for 750ms it waits only for 750us, which obviously causes that read temprature is not valid (it's default 85 degrees). --- extras/ds18b20/ds18b20.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extras/ds18b20/ds18b20.c b/extras/ds18b20/ds18b20.c index cb4a1d1..dc028fc 100644 --- a/extras/ds18b20/ds18b20.c +++ b/extras/ds18b20/ds18b20.c @@ -1,3 +1,6 @@ +#include "FreeRTOS.h" +#include "task.h" + #include "onewire/onewire.h" #include "ds18b20.h" @@ -29,7 +32,9 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) { onewire_reset(pin); onewire_select(pin, addr); onewire_write(pin, DS1820_CONVERT_T, ONEWIRE_DEFAULT_POWER); - sdk_os_delay_us(750); + + vTaskDelay(750 / portTICK_RATE_MS); + onewire_reset(pin); onewire_select(pin, addr); onewire_write(pin, DS1820_READ_SCRATCHPAD, ONEWIRE_DEFAULT_POWER); @@ -70,7 +75,7 @@ float ds18b20_read_single(uint8_t pin) { onewire_write(pin, DS1820_SKIP_ROM, ONEWIRE_DEFAULT_POWER); onewire_write(pin, DS1820_CONVERT_T, ONEWIRE_DEFAULT_POWER); - sdk_os_delay_us(750); + vTaskDelay(750 / portTICK_RATE_MS); onewire_reset(pin); onewire_write(pin, DS1820_SKIP_ROM, ONEWIRE_DEFAULT_POWER);