Open rpaulbeam opened 7 months ago
I made the following changes and the search algorithm detects both of my devices now. There may be a more elegant solution.
for (uint16_t rom_bit_index = 1; rom_bit_index < ((sizeof(onewire_device_address_t) * 8) +1); rom_bit_index ++) {
uint8_t rom_byte_index = (rom_bit_index-1) / 8;
uint8_t rom_bit_mask = 1 << ((rom_bit_index-1) % 8); // calculate byte index and bit mask in advance for convenience
it also fails for one device of DS18B20 :
The same sensor works in the arduino library for S3 but not the IDF library. Is there any quick hack that I can do?
What I did is here: https://github.com/espressif/idf-extra-components/issues/298
From: ramiws @.> Sent: Saturday, January 27, 2024 10:17 AM To: espressif/idf-extra-components @.> Cc: Paul Beam @.>; Author @.> Subject: Re: [espressif/idf-extra-components] Onewire search fails for devices with different bit 0 (IEC-83) (Issue #298)
it also fails for one device of DS18B20 :
The same sensor works in the arduino library for S3 but not the IDF library. Is there any quick hack that I can do?
— Reply to this email directly, view it on GitHubhttps://github.com/espressif/idf-extra-components/issues/298#issuecomment-1913184390, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARIKJB6INRPJO6AEB3OEM3DYQUK7ZAVCNFSM6AAAAABCDMHAZ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJTGE4DIMZZGA. You are receiving this because you authored the thread.Message ID: @.**@.>>
Answers checklist.
Which component are you using? If you choose Other, provide details in More Information.
onewire_bus
ESP-IDF version.
5.1.2
Development Kit.
ESP32-S3-DevKitC
Used Component version.
1.0.1
More Information.
onewire_device_iter_get_next() fails if the discrepancy occurs on bit 0. For multiple devices of the same family, this does not happen, but in my case I have a DS2408 and a MAX31820(same as ds18B20). At the beginning of the search (line69), last_zero is set to 0, but this is also used to test for the last device detected (line 111). So, it there is a real discrepancy at bit 0, the search takes the '1' direction, and then terminates thinking it has discovered all devices. The App Note referenced sets last_zero = 0, but uses bit_id = 1 as the start condition -- this implementation uses rom_bit_index which starts at 0.
This project is also for the esp32 and uses a bit_id that starts at 1: https://github.com/SuperHouse/esp-open-rtos/blob/master/extras/onewire/onewire.c I have not verified it works, but I am going to implement something similar. It is probably as simple as starting rom_bit_index at 1, and then dealing with all the -1s necessary to fix rom_bit_mask and rom_byte_index etc.