I came across a stash of iButton T-sense 1-wire sensors.. so I grabbed a couple and decided to check out 1-wire.
Maxim makes a 1-wire device called theĀ DS18B20. Itās a 9-12 bit temperature sensor with the possibility of being powered by parasitic power from the data line. This cuts the signal path down to a single DQ line and a return. A company called iButtonLink produces a nice little wrapper around this device called a T-Sense. There are a couple pieces of software out there that will allow you to hook these up to monitoring systems, I donāt have any though. These devices come with a 64-bit address code andĀ can be daisy-chained which makes having many of these devices monitored veryĀ nice.
At first I thought, ugh.. lame I have to send, and parse 64-bit codes in a little 8 bit micro.. doesnāt sound like a ton of fun for just fooling around on a day off.. thank fully they have a āSkip ROMā feature/command which works similar to a broadcast but can only be used when you have one device on the bus. If there is one thing left in this project I might consider finishing itād be to add the addressing in and daisy-chain a few of these.
Most of my research came from Microchipās Application Note AN1199Ā though the T-Sense Users Manual also helped out including determining the wiring diagram.
For my circuit I hooked up 5VDC (but later ran it on 3.3V just fine) and the 5VDC return on pins 1 & 2. Then the DQ link and return on pins 4&5. The signaling is interesting as the 1-wire bus needs a weak pull and works with an open collector circuits. The master starts all signaling, writes and reads. The 1ās and 0ās are based on how long the master or slave sinks the DQ line. To accomplish this in the PIC microcontroller I switched the port from an output to a three state input when I needed the port to be in weak-pull up mode (which is also hand when I need to sample the port for a response from a slave). The pull up on the resistor in my circuit is 10Kohm but Iāve seen 4.7KOhm and Iām sure anywhere in the neighborhood is fine. Finally if you do some digging youāll notice I run this in low speed mode, if I remember correctly the āhigh speedā mode is 4x faster. I donāt think speed of data transfer is really relevant when youāre waiting for 750ms for a temperature conversation though.
I initially started with just determining if there was a 1-wire device on the bus. If you perform a āresetā (master sinks the bus low for 480us then releases to hi-z for 70us and then performed a sample.. any (all) device(s) will sink the line slow to prove their presenceā¦then another 410us of delay before continuing. I got this one first try.. better luck than my first time with I2C! I then wrote the code (including sampling tidbits of Microchip AN1199 code to optimize) to do an actual temperature conversion and request it (by commanding a āread scratch padā). The device dumps all 9 bytes of itās registers. On that note I just remembered I should mention I did NOTHING with the CRC byte.. thatās all you if you care.
My temperature conversion code looks like this: (bus control m = master or PIC, s=slave or sensor)
m RESET
s PRESENCE flag
m SKIP ROM (0xCC)
m CONV TEMP (0x44)
m HOLD DQ (Hold line high 750ms for 12bit conversion .. I am guessing we hold it high for the parasitic power supply)
m RESET
s PRESENCE flag
m SKIP ROM (0xCC)
m READ SCRATCHPAD (0xBE)
s 9 Bytes of Data
and that looks likeā¦
For more detail: iButtonLink T-Sense 1-wire sensor (Maxim DS18B20) + PIC 18F14K22