The Dallas DS2406 is a versatile 1-Wire device providing both PIO lines and EPROM memory. This article discusses techniques and provides specific examples for interacting with the DS2406 using an Embedded Data Systems' HA7E 1-Wire Bus Master.
The general process for interacting with the DS2406 1-Wire device varies greatly from application to application, but the following attempts to demonstrate how to accomplish a variety of common functions on the DS2406 using Embedded Data Systems' HA7 1-Wire bus master.
The following are annotated examples of pseudo-code including the specific commands to send and typical responses received from the HA7E to access a variety of common DS2406 functions. In the examples below, TX= data transmitted to the HA7, and RX= data received from the HA7.
The datasheet on the DS2406 can be downloaded from here:
DS2406: Dual Addressable Switch
Discover the Device
In this example, the DS2406 is the only device on the 1-Wire bus so we simply use the 'S'earch Rom command to identify the first device:
|Performing a standard device search:|
Alternately, the 'F'amily search command could be used to discover all of the DS2406's as follows:
|Performing a family search for DS2406 devices:|
...and so on, until all the DS2406's have been enumerated at which point the 'f' command will simply return a carriage return.
Determining the state of any PIO line, including the activity latches, and both the sensed and active levels.
By simply examining the bits of the ChannelInfoByte which is returned when invoking the DS2406's ChannelAccess (0xF5) command, the current state of all the PIO lines on the DS2406 can be determined. For detailed information on the ChannelInfoByte, please refer to figure 9 on page 16 of the DS2406 datasheet. The following method can be used to read the ChannelInfoByte from the DS2406 without altering the exiting state of the PIO lines:
Reading the ChannelInfoByte from a DS2406 which provides lots of useful information.
|Start by addressing the DS2406 with ROM Id440000000F738912.|
Now invoke the DS2406's Channel Access Command (0xF5), passing a channel control byte value of 0x4C, which will return the ChannelInfoByte without altering the state of the PIO lines.
|Writing block of data: F54CFFFF.|
ChannelInfoByte Returned: 0x60
By examining the returned ChannelInfoByte, the following information can be determined about this DS2406:
|Based on bit 7, this DS2406 is obtaining power parasitically.|
|Based on bit 6, this is a DS2406P, with 2 PIO Channels.|
|Based on bit 5, the activity latch on PIO-B is not set.|
|Based on bit 4, the activity latch on PIO-A is set.|
|Based on bit 3, PIO-B Sensed Level is low.|
|Based on bit 2, PIO-A Sensed Level is low.|
|Based on bit 1, PIO-B is turned on (actively pulling the pin low).|
|Based on bit 0, PIO-A is turned on (actively pulling the pin low).|
Switching any PIO Line On or Off
The DS2406 contains either one or two PIO lines, depending on the exact model. These PIO lines are most commonly used for for simple discrete IO. The following examples demonstrate how to control the state of the PIO lines, as well as how to read the current state of the PIO lines. For information on how to detect the number of PIO lines supported on your particular DS2406, please see the preceding section of this document.
The easiest way to control the state of the PIO lines is by manipulating the status byte located in the DS2406 at memory address 7. The following examples all start by reading the current byte of data at that location, then manipulate the bits in question, then conclude by writing the new status byte back to the DS2406. By altering the existing status byte, other device settings that are stored in the status byte won't be accidentally altered.
Switching PIO_A Off:
|Read the existing status byte at memory address 7. Start by addressing the DS2406 having ROM Id 440000000F738912.|
|Now use the DS2406's Read Status Command (0xAA) to read the status byte from memory location 7.|
|Parsing the RX value above, we see the status byte returned is 0x1F. To switch PIO_A off, the status byte must have bit 5 set, so the new status byte is calculated to be 0x3F.|
|Now we write the new status byte back to memory location 7. Start by addressing the DS2406 having ROMId|
|Now use the DS2406's Write Status Command (0x55) to write the status byte back to memory location 7.|
The same technique can be applied to either turn on or off either PIO line by simply calculating the appropriate status byte, and writing it to memory location 7 in the DS2406. For details on the status byte, please refer to page 5 and 6 of the DS2406 datasheet.
Resetting the PIO Activity Latches
The DS2406 provides an activity latch on each PIO line that is set when a negative or positive edge occurs on the PIO line. In fact, the activity latch can be coupled to the DS2406's conditional seach feature, allowing for a scaleable method of detecting events occuring on the PIO lines. Resultantly, the DS2406 provides a method for resetting the activity latches, which is demonstrated with an HA7 here:
|Writing a ChannelControlByte of 0xCC to the DS2406 will reset the activity latches without altering any other settings on the PIO lines. Start by addressing the DS2406 having ROM Id 440000000F738912.|
|Now use the DS2406's Channel Access (0xF5) command to write the ChannelControlByte.|
Determine the Power Supply Status on the DS2406
The DS2406 supports two modes of power. The first is known as parasitic power, in which the device derives its power directly from the 1-Wire signal line. The second is known as external power, in which Vcc is supplied directly to the power pin on the DS2406. For more information regarding these two modes of operation, please refer to the DS2406 datasheet. The following method can be used to interrogate which mode the DS2406 is operating in, using the HA7E:
|Determining Power Supply Status by Examining bit 7 of the DS2406's Status Byte 7. Start by Addressing the DS2406 having ROM Id 440000000F738912.|
|Now issue the DS2406's 'Read Status' command (0xAA) to read status byte 7:|
|0x1F is the status byte returned. Bit 7 = 0|
In this example, the DS2406 is operating in parasitic power mode (0).
Article is closed for comments.