Open smacyas opened 6 years ago
I found to have the same issue however ONLY THE FIRST time around after reset/reboot. The ESP32 library is using the fastmicroseconds() as mentioned in expressif link above. To get around that the IRAM_ATTR had to be added. As I use the library on different boards and want to keep one source the following 3 changes can be applied:
in Onewire.h (around line 99) // Write a bit. The bus is always left powered at the end, see // note in write() about that.
void IRAM_ATTR write_bit(uint8_t v);
void write_bit(uint8_t v);
// Read a bit.
uint8_t IRAM_ATTR read_bit(void);
uint8_t read_bit(void);
in onewire.cpp (around line 204): change void OneWire::write_bit(uint8_t v) to
void IRAM_ATTR OneWire::write_bit(uint8_t v)
void OneWire::write_bit(uint8_t v)
in onewire.cpp (around line 236) change uint8_t OneWire::read_bit(void) to
uint8_t IRAM_ATTR OneWire::read_bit(void)
uint8_t OneWire::read_bit(void)
I can confirm the problem for the first incorrect reading when using ESP32. It has been so long that the bug is still there. And the above fixes the problem.
it works! I lost a day trying to understand why the "OneWireSerch" example does not work (it puts the search function in the setup, therefore it is performed only once after the reset, therefore ESP32 does not execute it) why not integrate it in the official library?
The solution offered in https://github.com/milesburton/Arduino-Temperature-Control-Library/issues/168#issuecomment-763158681 works for me. Tested with 1, 2 and 3 sensors. A bit of a hack having to call sensors.begin()
twice.
sensors.begin();
sensors.begin();
Used the same wiring setup as https://github.com/milesburton/Arduino-Temperature-Control-Library/issues/85#issuecomment-936510352 on an ESP32-PICO-MINI-02
EDIT: I contacted Maxim Integrated (manufacture of DS18B20 sensor) and found out my sensors are counterfeit, not sure if this is why they require the extra call or if the legit ones also have the same issue.
@PaulStoffregen could you merge one of the (similar) PRs addressing this issue on (multicore?) ESP32? I've verified with several instances that using IRAM_ATTR solves any issue that I had using OneWire on ESP32 regarding reading bus data.
After using the latest Arduino-esp32 there is a problem with ds18b20
Device is preset on the bus, bur ROM data error
https://github.com/espressif/arduino-esp32/issues/1335