Understanding 1-wire interface

1-wire devices are commonly used in many applications. You probably are familiar with famous DS18B20 digital temperature sensor in TO92 package. They can be powered and interfaced using same single data line plus ground return of course. 1-wire originally was designed by Dallas Semiconductors Corp. which is also a major provider of 1-wire devices like temperature sensors, timers, real time clocks, memory and well known iButton.

1-wire devices. DS18B20 and iButtons

1-wire interface is a bidirectional, half duplex slow serial communication standard. It doesn’t use any clock signal. When talking of speed, standard data rate is 15.4kbps. But there is possible to overdrive 1-wire communication to up to 125kbps.

1-wire signaling is based on one master and multiple slaves configuration. Each slave has a unique address stored on chip ROM. Master can recognize each slave by reading this address without any conflicts. The number of slaves may reach 100. But practically polling such number of slave devices would take long time. This should be taken in to account when designing responsive systems.

1-wire multiple slaves

Master and slave devices uses open collector (open drain) connection to bus line.

open drain or open collector

So there is a pull-up resistor needed. Normally 4.7k resistor is used to pull line up.

Powering modes of 1-wire devices

Most of 1-wire devices can be powered using two methods: parasitic and conventional. Parasitic mode is what enables signaling and powering devices via same data line. In this mode chips VCC pin must be connected to ground, while data line is pulled high through 4.7k resistor. During high signal state 1-wire devices internal 800pF capacitor is charged which ensures enough power during low state of line. Using parasitic more it is important to meet timing and power specifications in order to ensure enough power for proper operation. In some cases a helping hard pull-up may be used to provide enough power during data line inactivity (for instance during temperature conversion):

1-wire parasitic power

Since parasitic powering may not always be reliable way of powering, there is a conventional way by simply powering device with external power supply. This way instead of two wires you will need to trace three:

conventional power 1-wire

By powering devices with external power supply you can ensure safe operation even in higher temperature environments. Also you don’t need to include hard pull-up.

Communicating to 1-wire devices

Usually you won’t find a 1-wire interface in microcontrollers or PC. So in order to communicate you need to use software based bit-bang signaling or simply insert a 1-wire line driver which connects with one available interfaces like SPI or I2C. In most cases when microcontroller is used, 1-wire devices are interfaced directly to MCU pin(s). You can already find ready libraries for fast implementation, or simply write your own. Lets see how 1-wire signaling works. Once we clear things out, ti will be easy to write your own routines. In order to send binary numbers 1s or 0s there are time slots used. Depending on how long line is pulled low is recognized weather it is 0 or 1. Short time slot, when bus is released from low in 15us is considered as logical 1. While long slot at least 60us is 0. and in overdrive mode time slot durations are approximately 10 times shorter.

Communication is always started by master, which resets data line with long pull down (at least 480us). After master releases data line allowing pull-up resistor to pull data line high. After short period of time (up to 60us) slave devices pulls line to give a presence signal. This pull lasts a bit shorter than master reset (up to 240us). After slave releases data line, master starts communication.

1-wire signalling initialization

Master sends bits 0 and 1 by writing 60us time slots:

1-wire master data writing

When master is performing data write, it writs bits in 60us time slots. In order to write 0 it must pull data line low during all 60us time slot. Slave then detects low during sampling and reads 0. When master writing 1, it has to pull low for about 15us but not more and then release the line. Pull up resistor pulls up the line and slave during sampling detects high level and reads 1.

Master reading time slots:

1-wire master reading data diagram

During master read operation things get a little bit trickier, but not much. First of all master still controls read operation by pulling line low during read time slots. But this pull should be short (~1us) and then release the line. If slave sends 0 it keeps line pulled for the rest of time slot. Master should sample the data line after 15us to 60us. If master gets low signal then it must read 0. And again, during logical 1 read master pulls line for 1us and then releases. If after release slave doesn’t keep line pulled, pull-up resistor pulls data line up. Master should initiate sampling after like 15us to 60us. If it reads line high it must read 1.

Normally delay between time slots should be about 1us for normal recovery.

1-wire transaction consists of three parts. Otherwise it wouldn’t work.

1) 1-wire line reset;

2) ROM command sequence;

3) Function command sequence.

We already discussed the line reset. It gives a start of new signaling. ROM command enables to address slave device. There are several ROM commands with different purposes. You should look in devices datasheet for those. But few of them are common like Search ROM (F0h) where master identifies all slave devices connected to 1-wire data line. Each slave is equipped with unique 64-bit address. So master during ROM search cycles through all slaves reads and stores all 64-bit addresses. Each cycle starts with initialization (line reset). If there is a single slave connected, then master can use Read ROM (33h) command. When master has all ROM codes next time it can address slave by sending Match ROM (55h) command.

Third part of communication is Command sequence. This is where master sends speciffic commands to slave(s) like start conversion if temperature sensors are used, read temperature value from scratchpad memory and so on.

Next time we will try to put this theory in to practice.

One Comment:

  1. Hi! Thanks for the info with great details! We can offer good quanlity iButton keys and iButton probes with reasonable price. Take a look at our website: iButton.CC for more info. Feel free to contact us in any time.

Leave a Reply

Your email address will not be published. Required fields are marked *