Recent site activity

Welcome‎ > ‎

Maxim 1-wire drivers

posted 17 Jan 2010 13:40 by Chris Shucksmith   [ updated 17 Jul 2011 10:32 ]
I've developed a Java library to communicate with Maxim-IC "1-wire bus" devices. The test rig uses a USB -> serial port adapter (FDI) to interface at logic level with the DS2480 line driver. A bus driver was selected due to the shortcomings of driving 100m+ buses directly with MCU pins. To minimise signal reflection (ringing) rising and falling edges need be slew-rate limited and input voltage thresholds need ideally outside those used for (high-speed) logic interconnects. Maxm has an interesting article on bus design considerations including some scope traces of the analogue behaviour of 1 wire buses under various conditions:



Once the bus hardware is selected, the devices connected need to be identified, and this is where the software comes in.

Each device on the 1-wire bus has a unique 64-bit (8 byte) address etched by the manufacturer, unknown to the purchaser! Enumerating the entire address space to search for devices would take a long time: perhaps 2 ^ 64 * 1ms = ~ 584.9 million years! The bus design incorporates a "host discovery" facility where a 64 bit address is broadcast serially and listening devices indicate if they are "still listening" after each bit with a chirp. A host can enumerate rapidly, starting from an initial address, and quickly discard sub-trees of the address space that contain no devices. The discovery protocol details are fairly complex and recommendations speicified in 1-wire search algorithm, and briefly paraphrased here.  

At the start of discovery, all devices initialise a boolean state {participating,idle} to active and keep a count of discovered address bits 0-63. Each of the 64 bits is enumerated over four time slices: master-chipslave-0sslave-1smaster-decision. The master broadcasts during the first and last slots, slaves during the second and third. The master-chirp initiates each cycle. Devices in the [active] state chirp a reply during either the slave0 or slave1 timeslot, depending on the value at the current position in the device unique address. It is quite usual on populated buses for for multiple devices to chip concurrently in these timeslots. In the fourth slot the master indicates if it is exploring the zero or 1 sub-tree, and this causes de-selected devices (if any) to move from [participating] -> [idle]. The key to this process is that the master knows before taking a branch decision which of the two possible address space branches are populated (with at least one device). No time is spent exhausting empty sub trees. After 63 bits are enumerated, chirps signal individual devices, provided of course that the manufacturer does not reuse addresses!

In Java, I keep a queue of enumerable routes. Each discovery pass determines exactly one device, and generates possibly multiple branch points at which the search must continue to find the remaining device(s), putting them in a Queue. A sample run with two devices is show below:

Enumerating bus devices
 bus reset performed, state: PRESENCE_PULSE
 search bus command
 exploring route 0000000000000000
 sent: 00000000000000000000000000000000
 recv: aa820000000000080028080202890880
 route 0000000000000000 device f900000206211a28  discrepancies 0000000000000100
   discrepancy bit 8, adding route 0000000000000100
 bus reset performed, state: PRESENCE_PULSE
 search bus command
 exploring route 0000000000000100
 sent: 00000000000000000000000000020000
 recv: a2200000000000080028022802170880
 route 0000000000000100 device d400000206161128  discrepancies 0000000000000700
   discrepancy bit 9, adding route 0000000000000300
   discrepancy bit 10, adding route 0000000000000500
 bus reset performed, state: PRESENCE_PULSE
 search bus command
 exploring route 0000000000000300
 sent: 000000000000000000000000000a0000
 recv: 8200000000000008200002a88a8f0880
 route 0000000000000300 device 90000002401ebb28  discrepancies 0000000000000300
 bus reset performed, state: PRESENCE_PULSE
 search bus command
 exploring route 0000000000000500
 sent: 00000000000000000000000000220000
 recv: aa2a0000000000080aaa88aa28370880
 route 0000000000000500 device f70000023faf6528  discrepancies 0000000000000700
Found devices: [f900000206211a28, d400000206161128, 90000002401ebb28, f70000023faf6528]
Requesting conversion for f900000206211a28
 bus reset performed, state: PRESENCE_PULSE
 bus reset performed, state: PRESENCE_PULSE
Reading temperature for f900000206211a28
 bus reset performed, state: PRESENCE_PULSE
 scatchpad d81003ff7f464b014d
 crc 'd8' OK
 bus reset performed, state: PRESENCE_PULSE
 Temperature  20.8125 deg-C
Requesting conversion for d400000206161128
 bus reset performed, state: PRESENCE_PULSE
 bus reset performed, state: PRESENCE_PULSE
Reading temperature for d400000206161128
 bus reset performed, state: PRESENCE_PULSE
 scatchpad ff100eff7f464b0152
 crc 'ff' OK
 bus reset performed, state: PRESENCE_PULSE
 Temperature  21.1250 deg-C
Requesting conversion for 90000002401ebb28
 bus reset performed, state: PRESENCE_PULSE
 bus reset performed, state: PRESENCE_PULSE
Reading temperature for 90000002401ebb28
 bus reset performed, state: PRESENCE_PULSE
 scatchpad 03100eff7f464b0162
 crc '03' OK
 bus reset performed, state: PRESENCE_PULSE
 Temperature  22.1250 deg-C
Requesting conversion for f70000023faf6528
 bus reset performed, state: PRESENCE_PULSE
 bus reset performed, state: PRESENCE_PULSE
Reading temperature for f70000023faf6528
 bus reset performed, state: PRESENCE_PULSE
 scatchpad a31006ff7f464b015a
 crc 'a3' OK
 bus reset performed, state: PRESENCE_PULSE
 Temperature  21.6250 deg-C

To-do list:
  • consider devices that disconnect during a search, and/or brown-out
  • driver needs code to switch the DS2480 into flexible driver mode and set recommended long-line parameters
  • validate CRCs