Browse Source

Support for parasitic power - WIP.

main
David Antliff 6 years ago
parent
commit
19d8b0e625
  1. 2
      CMakeLists.txt
  2. 2
      components/esp32-ds18b20
  3. 25
      main/app_main.c

2
CMakeLists.txt

@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp32-ds18b20-example) project(esp32-ds18b20-example LANGUAGES C)
if (NOT IDF_VERSION_MAJOR) if (NOT IDF_VERSION_MAJOR)
set(IDF_VERSION_MAJOR 3) set(IDF_VERSION_MAJOR 3)

2
components/esp32-ds18b20

@ -1 +1 @@
Subproject commit d76b70c0a795adbbd1b9d1b3e2789b455cfd945d Subproject commit ae81f86e0ee1cd65b6d6a2ad59deb7ba295ab3c4

25
main/app_main.c

@ -22,8 +22,6 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <inttypes.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_system.h" #include "esp_system.h"
@ -38,10 +36,11 @@
#define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT) #define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT)
#define SAMPLE_PERIOD (1000) // milliseconds #define SAMPLE_PERIOD (1000) // milliseconds
void app_main() _Noreturn void app_main()
{ {
// Override global log level // Override global log level
esp_log_level_set("*", ESP_LOG_INFO); 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: // To debug, use 'make menuconfig' to set default Log level to DEBUG, then uncomment:
//esp_log_level_set("owb", ESP_LOG_DEBUG); //esp_log_level_set("owb", ESP_LOG_DEBUG);
@ -150,6 +149,14 @@ void app_main()
// vTaskDelay(1000 / portTICK_PERIOD_MS); // 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 // Read temperatures more efficiently by starting conversions on all devices at the same time
int errors_count[MAX_DEVICES] = {0}; int errors_count[MAX_DEVICES] = {0};
int sample_count = 0; int sample_count = 0;
@ -157,15 +164,21 @@ void app_main()
{ {
TickType_t last_wake_time = xTaskGetTickCount(); TickType_t last_wake_time = xTaskGetTickCount();
while (1) while (1) {
{
last_wake_time = xTaskGetTickCount(); last_wake_time = xTaskGetTickCount();
ds18b20_convert_all(owb); ds18b20_convert_all(owb);
// In this application all devices use the same resolution, // In this application all devices use the same resolution,
// so use the first device to determine the delay // 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 // Read the results immediately after conversion otherwise it may fail
// (using printf before reading may take too long) // (using printf before reading may take too long)

Loading…
Cancel
Save