PaulStoffregen / OneWire

Library for Dallas/Maxim 1-Wire Chips
http://www.pjrc.com/teensy/td_libs_OneWire.html
579 stars 382 forks source link

OneWire malfunction on ESP32-S2 ? #122

Open hervmele opened 1 year ago

hervmele commented 1 year ago

Description

I am currently working with ESP32-S2FN4R2 on a LOLIN S2 PICO board.

I am using OneWire library to connect DS18B20 (with Rob Tillaart DS18B20 library)... not very original !

I tried to use GPIO36 for Dallas chip connection ... but initial DS18B20::begin failed (false return)...

I tried to use another neighbor GPIO (35..38) with same result.

BUT, all seems ok with low numbered GPIO pins...

"begin" method call onWire search method to look for devices on "One Wire" bus.

I looked on library code and found that piece of code in OneWire_direct_gpio.h


static inline attribute((always_inline)) void directModeOutput(IO_REG_TYPE pin) {

if CONFIG_IDF_TARGET_ESP32C3

GPIO.enable_w1ts.val = ((uint32_t)1 << (pin));

else

if ( digitalPinIsValid(pin) && pin <= 33 ) // pins above 33 can be only inputs
{

if ESP_IDF_VERSION_MAJOR < 4 // IDF 3.x ESP32/PICO-D4

    uint32_t rtc_reg(rtc_gpio_desc[pin].reg);

    if ( rtc_reg ) // RTC pins PULL settings

You can see that pin > 33 are excluded because "only inputs"...

It's true for ESP32, but not for ESP32-S2 (i don't know for ESP32-S3)...

I tried that little workaround...


if ( digitalPinIsValid(pin) /*&& pin <= 33*/ ) // pins above 33 can be only inputs

and my DS18B20 started talking on GPIO 36 !

So i think that OneWire Code should have special case for ESP32-S2 (may be S3 too)...

Sorry if i made mistake !

Steps To Reproduce Problem

Need ESP32S2 board and DS18B20 to be connected with.

Hardware & Software

Board LOLIN S2 PICO (or other S2 board i think !) Shields / modules used Arduino IDE version (i am working with PIO Core 6.1.5·Home 3.4.3) Teensyduino version (if using Teensy) Version info & package name (from Tools > Boards > Board Manager)... platformio ini file ; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html

[env:lolin_s2_pico]
platform = espressif32
board = lolin_s2_pico
framework = arduino
board_build.flash_mode = qio
lib_deps = 
paulstoffregen/OneWire@^2.3.7
robtillaart/DS18B20@^0.1.12

Operating system & version Win 10 / VS Code / Platformio Any other software or hardware? Of course DS18B20 devices need to be connected on board 11 and 36 GPIO pin !

Arduino Sketch (PIO code)

include

include

include

OneWire oneWire36 (36); // DS18B20 on >33 GPIO DS18B20 tempSensor36 (&oneWire36);

OneWire oneWire11 (11); // DS18B20 on low numbered GPIO DS18B20 tempSensor11 (&oneWire11);

void setup () { // Serial init and wait for terminal

Serial. begin (115200);

while (Serial. available () == 0) yield ();

Serial. println ("go...");

if (tempSensor11. begin ()) Serial. println ("DS18B20 OK on GPIO11"); else Serial. println ("DS18B20 KO on GPIO11");

if (tempSensor36. begin ()) Serial. println ("DS18B20 OK on GPIO36"); else Serial. println ("DS18B20 KO on GPIO36"); }

void loop () { }

outdever commented 1 year ago

In ESP32-S3 I used it on pin 48, I also had to change lines like: else if ( pin < 46 ) to else It was 135, 150, 163 lines