circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

May 1999, Issue 106

Dallas 1-Wire Devices, (Part 2):
All on One


by Jeff Bachiochi

CLIMBING THE TREE

Think first of a tree on its side with the base of the trunk on the left. A short distance from the trunk, it splits off into two branches; one bends upward, the other downward.

A little further on, those two branches split again, which is the second bit division in our search. And so it goes for 64 (bit) divisions (8 bytes worth).

This scenario gives you an idea of the massive number of possibilities. To keep things straight, at every division, label the branch paths that bend up 1, and the branches that bend down 0. Following the bottom path, all the branches are labeled 0. This is the path we take to identify a 1-wire device with all 0s for its family byte, six ID bytes, and CRC.

To help determine who’s there, Dallas takes advantage of the open-collector architecture of the 1-wire bus. When SEARCH-ROM is issued (following a RESET timeslot), you must read a time slot twice. All 1-wire devices that are not disabled (hold that thought) answer first with their present address bit (address first) and then with the complement of that address bit.

There are four possible outcomes to these two reads: 11, 10, 01, and 00. Two 1s indicate that no devices were present. There must be complementary bits if a single device answers 01 or 10.

When multiple devices are present, they may both have the same or opposite address bits in the present position. If they are the same, you won’t be able to differentiate between them at this present bit position. Don’t worry about that now. It will all work out later. If they are different, each one forces a 0 on the bus and you know that there is an address conflict at this fork.

From this information, you must choose a path to take. Naturally, if there are no address conflicts, you choose that path on the tree. If there is a conflict, you can choose either path, but remember to come back to this branch later and follow it to find the complete address for the conflicting device.

Choose a path by sending a write-1 or write-0 time slot. All devices that have conflicting bits at this position are disabled until you issue another RESET. These devices are now off the bus for the rest of this path search.

Repeat this combination of double reads with a decision path write until all 64 bits are searched. You now know that there is a device on the bus with the 64-bit address of the path you just completed.

Now, you must reset the bus and do a new search to resolve any conflicts you found along the way. To keep track of where you’ve been, try this method.

Always take the lower path of any conflict first. Keep track of the last conflict in a path and resolve that conflict on the next path. When you get to the 64th bit of each search, if you’ve had no conflicts on the present search, you’re finished.

The program in Listing 1 uses the assembly routines from last month to search for all the devices on the 1-wire bus. The program follows the flowchart in the Dallas 1-wire databook.

The 1-wire weather station has a few unique points that are worth discussing here. The first is a 1-wire device with controllable I/O bits. The DS2407 has two I/O bits, which can be set or cleared through the 1-wire bus.

In the weather station, this device enables or disables eight 1-wire serial number chips. When it is disabled, all eight devices are disconnected from signal ground and unable to communicate. When it is enabled, each device’s data pin can be connected to the 1-wire bus when a magnet closes a reed switch.

A wind vane positions a magnet over one of the reed switches (which are set in a circle around the vane’s center of rotation). When the magnet closes the reed switch, the device is connected to the 1-wire bus and its serial number can be read.

Each of the eight devices corresponds to one of the eight compass directions. One of these devices is popping on and off the bus as the wind changes direction. Of course, you must know which serial numbers indicate which direction before the weather station can be used.

With all of this data, you may notice there are two ways to determine wind direction. You can attempt to use MATCH-ROM to determine whether or not each device is attached, or you can use SEARCH-ROM to determine which one is there. Figure 1 shows the output produced by running the search program in Listing 1.