iButtonLink T-Sense 1-wire sensor (Maxim DS18B20) + PIC 18F14K22

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.

iButtonLink T-Sense 1-wire sensor

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

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter