Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onewire search fails for devices with different bit 0 (IEC-83) #298

Open
3 tasks done
rpaulbeam opened this issue Jan 20, 2024 · 3 comments
Open
3 tasks done

Onewire search fails for devices with different bit 0 (IEC-83) #298

rpaulbeam opened this issue Jan 20, 2024 · 3 comments
Labels

Comments

@rpaulbeam
Copy link

Answers checklist.

  • I have read the component documentation ESP-IDF Components and the issue is not addressed there.
  • I am using target and esp-idf version as defined in component's idf_component.yml
  • I have searched the issue tracker for a similar issue and not found any related issue.

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.

@rpaulbeam rpaulbeam added the Type: Bug Bugs in components label Jan 20, 2024
@github-actions github-actions bot changed the title Onewire search fails for devices with different bit 0 Onewire search fails for devices with different bit 0 (IEC-83) Jan 20, 2024
@rpaulbeam
Copy link
Author

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

@ramiws
Copy link

ramiws commented Jan 27, 2024

it also fails for one device of DS18B20 :

https://www.lcsc.com/product-detail/Temperature-Sensors_UMW-Youtai-Semiconductor-Co-Ltd-DS18B20_C376006.html

The same sensor works in the arduino library for S3 but not the IDF library. Is there any quick hack that I can do?

@rpaulbeam
Copy link
Author

rpaulbeam commented Jan 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants