There are wide range of 1-Wire sensors based off of Maxim Integrated's DS2438. The OW-SERVER v2 presents much of the DS2438 data within its XML tags along with a calculation of the humidity assuming the DS2438 is a TAI8540D. This knowledge base article discusses how to work with the DS2438 sensor and an OW-SERVER v2 bus master using the low level commands. Using the low level commands gives the programmer greater flexibility in how the sensor is read.
The general process for interacting with DS2438 based sensors is as follows:
- Discover the Device
- Read Status/Configuration Register
- Parse the results
- Initiate the temperature conversion
- Wait for the conversion to complete
- Read the results
- Parse the results
- Configure AD Bit
- Wait for NV Write Cycle
- Initiate the second voltage conversion
- Wait for the conversion to complete
- Read the results
- Parse the result
The following is an annotated example of the specific commands to send and typical responses received from the OW-SERVER v2 to accomplish the steps above. In the examples below, TX= data transmitted to the OW-SERVER v2, and RX= data received from the HA7. This example is written for a DS2438 having ROMId 'DC0000006CC62126'. The manufacturer's datasheet on the DS2438 can be downloaded from http://short.eds.bz/ds2438-datasheet.
Discover the Devices
In this example, the ds2438 is the only device connected to port 1 so we simply use the 'S'earch Rom command to identify the first device:
TX- S1 | Performs a standard device search on port 1. |
RX- DC0000006CC62126 | The ROM Id of the ds2438. |
TX- R1 | Reset the bus on port 1. |
RX- P | Presence Pulse received. |
Read Status/Configuration Register
TX- A1DC0000006CC62126 | Address the device having ROMId DC0000006CC62126 on port 1. |
RX- + | Command accepted |
TX- W1B800 | Writing block of data: B800 |
RX- B800 | |
TX- R1 | Reset the bus on port 1. |
RX- <CR> | |
TX- A1DC0000006CC62126 | Address the device having ROMId DC0000006CC62126 on port 1. |
RX- + | Command accepted |
TX- W1BE00FFFFFFFFFFFFFFFF | Writing block of data on port 1: BE00FFFFFFFFFFFFFFFF |
Rx- BE000F0B467FFF101092 | |
TX- R1 | Reset the bus on port 1. |
RX- P | Presence Pulse received. |
Parse the results
Based on the DS2438 Memory Map on page 15 of the datasheet, we can parse the scratchpad bytes returned above to determine the following:
Bit 0 = IAD = Current A/D Control Bit
Bit 1 = CA = Current Accumulator Configuration
Bit 2 = EE = Current Accumulator Shadow Selector bit
Bit 3 = AD = Voltage A/D Input Select Bit
Bit 4 = TB = Temperature Busy Flag
Bit 5 = NVB = Nonvolatile Memory Busy Flag.
Bit 6 = ADB = A/D Converter Busy Flag.
Bit 7 = X = Don’t care
For most sensor applications, a combination of Temperature, VAD, VDD, and/or VSens are used. Bit 0 (IAD) determines if the current readings are updating at a rate of 36.41Hz. The default "1" is enabled. Writing the bit to "0" would disable the updating. Bit 3 (AD) identifies whether a voltage conversion reads the VDD or VAD. The default "1" selects the VDD. Writing the bit to "0" reads the VAD.
Initiate Temperature ConversionThe temperature conversion process on the ds2438 is initiated by transmitting command byte '0x44' to the device, as follows:
TX- A1DC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | |
TX- W144 | Writing block of data: 0x44. |
RX- 44 | |
TX- R1 | Reset the bus |
RX- P | Presence Pulse received. |
Wait for conversion
You must now wait 10mS for the conversion to take place before you can read the results back from the device. If the ds2438 is being powered parasitically, then no other activity can occur on the 1-Wire bus during the temperature conversion, or the ds2438 will be power starved. Note that the HA7 automatically provides strong pull-up power on the 1-Wire bus during the conversion.
Initiate the first voltage conversion
TX- ADC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W1B4 | Writing block of data: 0xB4. |
RX- B4 | |
TX- R1 | Reset the bus |
RX- P | Presence Pulse received. |
Read the Results
The resulting temperature is stored in the ds2438's scratchpad memory. To obtain the temperature data, simply read the scratchpad from the device and parse the temperature data out of the scratchpad. For complete details on how the temperature data is encoded into the scratchpad, please refer to the ds2438 datasheet.
Reading the ds2438's scratchpad.
TX- ADC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W1B800 | Writing block of data: B800 |
RX- B800 | |
TX- R1 | Reset the bus |
RX- P | Presence Pulse received. |
TX- ADC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W1BE00FFFFFFFFFFFFFFFFFF | Writing block of data: BE00FFFFFFFFFFFFFFFFFF. |
RX- BE000FD016DE01D80100 | Scratchpad data |
TX- R1 | Resetting 1-Wire bus. |
RX- P | Presence Pulse received. |
The read above returned the following scratchpad bytes: 0FD016DE01D80100FF.
Parse the Results
Based on the DS2438 Memory Map on page 6 of the datasheet, we can parse the scratchpad bytes returned above to determine the following:
Byte 0 = STATUS/CONFIGURATION = 0x0F
Byte 1 = TEMPERATURE LSB = 0xD0 = 208
Byte 2 = TEMPERATURE MSB = 0x16 = 22
Byte 3 = VOLTAGE LSB = 0xDE = 222
Byte 4 = VOLTAGE MSB = 0x01 = 1
Byte 5 = CURRENT LSB = 0xD8 = 216
Byte 6 = CURRENT MSB = 0x01 = 1
Byte 7 = THRESHOLD = 0x00
Byte 8 = CRC = 0xFF
Temperature is signed and formatted such that Byte_2 holds the integer number of centigrade degrees in the least significant 7 bits. Bit 8 is the sign bit and when the sign bit is set the value of the Byte_2 and Byte_1 must be inverted. Byte_1 always describes the fractional part of the temperature in units of 0.00390625 = (2^-8). The routine can be used to interpret the value.
if (Byte_2 & 0x80) {
// Negative Temperature
TempWhole = ~Byte_2
TempFrac = ((~Byte_1) & 0xF8) * (2^-8)
Temp = -1 * (TempWhole + TempFrac)
}
else {
// Positive Temperature
TempWhole = Byte_2
TempFrac = (Byte_1 & 0xF8) * (2^-8)
Temp = Byte_2 + TempFrac
}
The algorithm applied
// Positive Temperature
TempWhole = 22
TempFrac = (208 & 0xF8) * (2^-8) = 0.8125
Temp = 22 + 0.8125 = 22.8125
Temperature = Temp and is expressed in C
The Voltage Bytes reflect the VDD as determined by the AD bit.
Supply Voltage (VDD) = ((Byte_3 + (Byte_4 * 0xFF)) & 0x3FF) * 0.01
Supply Voltage (VDD) = ((222 + (1 * 256)) & 0x3FF) * 0.01 = 4.78
Configure AD Bit
The status configuration byte was 0x0F on the last read. To change the AD bit (Bit 3) to "0". The following command can be used to set the bit 3 to "0" while setting IAD, CA & EE to defaults. Setting IAD bit to the default value of "1" would start the current readings updating. However, current readings were already updating in this example.
TX- A1DC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W14E0007 | Writing block of data: 4E0007 (Write Scratchpad) |
RX- 4E0007 | |
TX- R1 | Reset the bus. |
RX- P | Presence Pulse received. |
TX- A1DC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W14800 | Writing block of data: 4800 (Copy Scratchpad) |
RX- 4800 | |
TX- R1 | Reset the bus. |
RX- P | Presence Pulse received. |
Wait for NV Write Cycle
You must wait 10mS for NV write cycle to be to be completed.
Initiate the second voltage conversion
TX- A1DC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W1B4 | Writing block of data: 0xB4. |
RX- B4 | |
TX- R1 | Reset the bus |
RX- P | Presence Pulse received. |
Read the results
Reading the ds2438's scratchpad.
TX- A1DC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W1B800 | Writing block of data: B800 |
RX- B800 | |
TX- R | Reset the bus |
RX- P | |
TX- A1DC0000006CC62126 | Addressing Device having ROMId DC0000006CC62126. |
RX- + | Command accepted |
TX- W1BE00FFFFFFFFFFFFFFFFFF | Writing block of data: BE00FFFFFFFFFFFFFFFFFF. |
RX- BE0007D016DE01D80100 | Scratchpad data. |
TX- R | Resetting 1-Wire bus. |
RX- P | Presence Pulse received. |
Parse the Results
Based on the DS2438 Memory Map on page 6 of the datasheet, we can parse the scratchpad bytes returned above to determine the following:
Byte 0 = STATUS/CONFIGURATION = 0x07
Byte 1 = TEMPERATURE LSB = 0xD0 = 208
Byte 2 = TEMPERATURE MSB = 0x16 = 22
Byte 3 = VOLTAGE LSB = 0xDE = 222
Byte 4 = VOLTAGE MSB = 0x01 = 1
Byte 5 = CURRENT LSB = 0xD8 = 216
Byte 6 = CURRENT MSB = 0x01 = 1
Byte 7 = THRESHOLD = 0x00
Byte 8 = CRC = 0xFF
The Voltage Bytes reflect the VAD as determined by the AD bit.
General Purpose A/D Voltage (VAD) = ((Byte_3 + (Byte_4 * 0xFF)) & 0x3FF) * 0.01
General Purpose A/D Voltage (VAD) = ((222 + (1 * 256)) & 0x3FF) * 0.01 = 4.78
When IAD bit is "1" the VSens readings are being calculated.
VSens (Current) = ((Byte_5 + (Byte_6 * 0xFF)) & 0x3FF) * 0.0002441
VSens (Current) = ((216 + (1 * 256)) & 0x3FF) * 0.0002441 = 0.1152
The VSens reads the voltage drop over a know resistance. This data can be used to calculate the current.
Comments
0 comments
Article is closed for comments.