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