From 19d8b0e625e9e088800b02d56f0f6c198cce8a81 Mon Sep 17 00:00:00 2001 From: David Antliff Date: Thu, 23 Apr 2020 15:36:45 +1200 Subject: [PATCH] Support for parasitic power - WIP. --- CMakeLists.txt | 2 +- components/esp32-ds18b20 | 2 +- main/app_main.c | 25 +++++++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31da009..f0e3c48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(esp32-ds18b20-example) +project(esp32-ds18b20-example LANGUAGES C) if (NOT IDF_VERSION_MAJOR) set(IDF_VERSION_MAJOR 3) diff --git a/components/esp32-ds18b20 b/components/esp32-ds18b20 index d76b70c..ae81f86 160000 --- a/components/esp32-ds18b20 +++ b/components/esp32-ds18b20 @@ -1 +1 @@ -Subproject commit d76b70c0a795adbbd1b9d1b3e2789b455cfd945d +Subproject commit ae81f86e0ee1cd65b6d6a2ad59deb7ba295ab3c4 diff --git a/main/app_main.c b/main/app_main.c index d0705ec..14c99b9 100644 --- a/main/app_main.c +++ b/main/app_main.c @@ -22,8 +22,6 @@ * SOFTWARE. */ -#include - #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" @@ -38,10 +36,11 @@ #define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT) #define SAMPLE_PERIOD (1000) // milliseconds -void app_main() +_Noreturn void app_main() { // Override global log level esp_log_level_set("*", ESP_LOG_INFO); + esp_log_level_set("*", ESP_LOG_DEBUG); // To debug, use 'make menuconfig' to set default Log level to DEBUG, then uncomment: //esp_log_level_set("owb", ESP_LOG_DEBUG); @@ -150,6 +149,14 @@ void app_main() // vTaskDelay(1000 / portTICK_PERIOD_MS); // } + // Check for parasitic-powered devices that require a strong-pullup + bool require_strong_pullup = false; + ds18b20_check_for_parasite_power(owb, &require_strong_pullup); + printf("Strong pullup (parasitic power) %srequired\n", require_strong_pullup ? "" : "not "); + if (require_strong_pullup) + { + } + // Read temperatures more efficiently by starting conversions on all devices at the same time int errors_count[MAX_DEVICES] = {0}; int sample_count = 0; @@ -157,15 +164,21 @@ void app_main() { TickType_t last_wake_time = xTaskGetTickCount(); - while (1) - { + while (1) { last_wake_time = xTaskGetTickCount(); ds18b20_convert_all(owb); // In this application all devices use the same resolution, // so use the first device to determine the delay - ds18b20_wait_for_conversion(devices[0]); + if (require_strong_pullup) { + ets_delay_us(750000); + gpio_set_level(5, 0); + } + else + { + ds18b20_wait_for_conversion(devices[0]); + } // Read the results immediately after conversion otherwise it may fail // (using printf before reading may take too long)