cybergibbons / DS2482_OneWire

A OneWire library using the DS2482 I2C->1-Wire bridge
29 stars 25 forks source link

Possible fix to wireSearch missing devices. #12

Open tekkydave opened 3 years ago

tekkydave commented 3 years ago

Are you aware of a fix provided by Close20 in an answer on: Stack Exchange

I have applied this fix to a local copy of the library and it seems to solve an issue I was having with 3 devices on the bus. It worked fine with 2 devices

280E6DB901000059 26F488170100002F

but when I added

1D310A0900000037

It became the only device found

After applying Close20's fixes all 3 devices are found.

I thought I would pass this on in case it is useful to you and others. Thanks for the library. It's been a great help to me. Dave

I believe the library linked by Cybergibbons has a bug in

uint8_t OneWire::wireSearch(uint8_t *address)

A discrepancy at i = 0 (bit zero in this library, id_bit_number = 1 in a Maxim example) only follows
the direction = 1 path and fails to find ROM addresses where bit zero = 0 (i.e. even family codes
are missed when mixed devices, some with even and others with odd family codes, are present
on the 1-wire bus).

A fix I have just implemented and appears to work is to modify the library to declare
searchLastDiscrepancy and last_zero as int8_t (not uint8_t), initialise/reset them to -1 (not zero) and,
near the end of the method

if (!last_zero) searchLastDeviceFlag = 1;


becomes

if (last_zero == -1) searchLastDeviceFlag = 1;