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-chip, slave-0s, slave-1s, master-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:
To-do list:
Implementation http://code.google.com/p/jprinterface/source/browse/trunk/ecolux-client/src/org/cscs/interfaces/CommDriverDS2480B.java |
