What is the 1-Wire protocol? (2024)

Table of Contents
You may also like: Next Article

The 1-Wire protocol is a single-wire interface, half-duplex, bidirectional, low-speed and power, long-distance serial-data communication protocol. Although this protocol is classified as a 1-wire standard, at least two wires are required in the 1-wire standard bus — one for the data and/or power supply and another for the ground return. An additional wire might be necessary, depending on the power mode.

A 1-wire standard has a master and slave configuration, where there can only be one master device, a computer or microcontroller, and several slave devices. It’s possible to connect up to 100-slave, 1-wire devices, with a 1-wire standard bus. However, as slave devices are added to the bus, their polling by the master device might take more time.

This protocol does not use a clock signal. Instead, the slave devices are internally clocked and synchronized with a signal from the master device. The master device is solely responsible for the read and write operations of the slave devices, so they cannot initiate a data transfer on their own. What they can do is indicate their presence over the bus when the master resets.Every master device is identified by a 64-bit address, stored within each one-wire slave device’s ROM.

This is a low-speed serial communication standard, with a typical data speed of 15.4 kbps. The bus can be overdriven to a maximum data speed of 125 kbps. The data speeds in the 1-Wire protocol are low compared to other standard serial-data communication protocols (like UART, I2C, and SPI), but the 1-wire bus is extremely economical in production and operation. It offers a simple hardware implementation and an extremely low-power footprint.

Although the hardware is simple, the software implementation on the microcontroller side is highly complex. And despite a low power consumption, it can communicate data over relatively long distances.

The 1-Wire protocol is used by temperature sensors, real-time clocks, timers, EEPROMs, and the popular iButton. Most of these 1-wire slave devices are products of (what’s now) Maxim Integrated.

Let’s discuss in more detail.

What is the 1-Wire protocol?
The 1-Wire protocol is a single-wire interface for low-speed data communication in microcontrollers and computers. The protocol operates over a single data line without a clock signal. It’s a master-slave serial communication protocol where the half-duplex bidirectional data communication with multiple slaves is solely managed and controlled by a single master.

The 1-wire standard bus
The 1-wire standard bus has at least two wires. One is the data line and the other is the ground return. Both master and slaves have an open-drain (open-collector) connection with the data line. This is why a 4.7K resistor typically pulls the data line up. There are two possible powering modes for the 1-wire slave devices: parasitic and conventional.

In parasitic mode, only the data line and ground return must be traced to the 1-wire slave device. If the conventional power mode is used, an additional positive supply line must be traced to each 1-wire slave connected to the bus.

Therefore, the 1-wire bus on a PCB might have two or three lines. The conventional powering with three lines in the 1-wire bus is more reliable.

Parasitic Vs. conventional power
As mentioned, 1-wire slave devices can be powered in parasitic and conventional modes. All 1-wire slave devices have three terminals: VDD, GND and data. In the parasitic mode, the VDD and GND pins are connected to the ground, so the signal and power are supplied to the slave devices on the same line (i.e. the data line).

The slave devices have an internal capacitor of 800 pF, which gets charged when the data line is HIGH. The stored charge keeps the slave live when the data line is LOW. The data line is typically pulled up by a 4.7K resistor.

Parasitic powering requires strict timing and supply to the exact specification to maintain the slave device live without fail. This is why this mode is less reliable. Often, an additional hard pull-up is used to ascertain the power supply.

What is the 1-Wire protocol? (1)

The parasitic powering of 1-wire devices.

In a conventional powering mode, 1-wire slave devices are externally powered. An additional wire is traced to each 1-wire slave. The external power supply to the slaves ensures safe operation even in harsh, high-temperature conditions.

What is the 1-Wire protocol? (3)

The conventional powering of 1-wire devices.

Typical 1-wire devices operate in voltages from – 1.71~1.89V, 1.71~3.63V, 2.97~6.63V, and 2.97~5.25V. The current drawn ranges between 1.06~5mA. The pull-up resistor sets the current level whether devices are supplied parasitic or conventional power.

How the 1-Wire protocol works
This interface is not usually used in microcontrollers or microcomputers. It’s often implemented by software using bit-banging or a universal asynchronous receiver-transmitter (UART).

Communication over the data line is initiated by the master using a reset. It pulls down the data line for 480 us and then releases it, allowing the typical pull-up resistor to pull the data line HIGH. If slave devices are connected to the bus, they respond to the reset signal by pulling the data line LOW for 60~240 us. If the line is pulled down by the slave(s), the master confirms their presence over the bus. After 60~240 us, the slave(s) release the data line, so the master can start writing.

What is the 1-Wire protocol? (4)

After a reset, the master can write and read data with the slave devices. Initially, it sends ROM commands, like the search ROM command (0xF0), to access the ROM address of the slave devices. After reading the ROM addresses of all the connected 1-wire slave devices, the master device can access one by sending the Match ROM command (0x55). The ROM commands are followed by the function ones.

For example, if a 1-wire temperature sensor is connected to the bus, the microcontroller can send the function commands to start the temperature conversion, read the temperature, etc. The ROM and function commands are 8-bit long.

Since the 1-Wire standard does not use any clock signal, communication of the ‘0’ and ‘1’ bits occur by setting the logical level of the data line for a specific time slot. Usually, the time slot is 60 us long. There’s also an interval of 1us between each time slot, so that the data line is pulled HIGH again by the pull-up resistor. During each 60 us time slot, 1 bit is communicated between the master and slave. The time slot can be up to 10 times shorter if the bus is overdriven.

When the master has to write bits over the data line, it pulls the data line down.

  • To write ‘0,’ the master pulls down the data line for the full 60 us time slot, then releases it for a 1us interval between the time slots.
  • To write ‘1,’ the master pulls the data line down for a shorter period of 15 us, during the entire time slot, then releases it for a 1us interval between the time slots.

The slave devices pulse at about the mid-time slot (i.e. 30us in the 60us time slot). They have a basic monostable multivibrator to detect the duration of the pulses. The ROM and function commands are 8-bit long. The data communicated is also in groups of 8 bits. The error detection is performed by an 8-bit cyclic redundancy check.

The master reads from the slave device after sending a ROM search or function command. The read operation is controlled by the master device. The master reads from the slave bit-by-bit while data is communicated to the master in groups of 8 bits. Each bit is read in a 60 us time slot (or shorter if the bus is overdriven).

The master pulls the data line down for 1 us and releases it. Then, it samples the data from the bus after 15 us. If the slave writes ‘0’ over the bus, it keeps the line pulled down for the full 60 us of time slot, and then releases the data line for a 1us interval between the time slots. If the slave writes ‘1’over the bus, it keeps the line pulled down for 15 us, and then releases the data line for the pull-up resistor to pull the data line HIGH.

The master samples each bit after 15 us. If the bit sent by the slave is ‘0,’ the line is pulled LOW at the time of sampling. If the bit sent by the slave is ‘1,’ the line is pulled HIGH at the time of sampling.

The master can communicate with up to 100 slaves on a 1-wire standard bus. However, the greater the number of 1-wire slaves connected to the bus, the more time the master needs to pull data from them. The software libraries typically use bit-banging or the UART to time pulse durations. The LSB is always sent first in the 1-Wire protocol.

Protocol implementation
There are five types of bus signals in 1-wire communication, and each one is initiated and controlled by the master. These signals are Reset, Presence, Write 0, Write 1, and Read.

The protocol can be implemented by a microcontroller or computer in two ways: polled and interrupt-driven implementation. Polled is a software-only implementation. The interrupt-driven implementation requires a built-in timer/counter.

In terms of Arduino, the polled implementation (software-only) can be done using the delayMicroseconds() function. This function has this source code:

void delayMicroseconds(unsigned int us)
{
// calling avrlib’s delay_us() function with low values (e.g. 1 or
// 2 microseconds) gives delays longer than desired.
//delay_us(us);
// for the 16 MHz clock on most Arduino boards
// for a one-microsecond delay, simply return. the overhead
// of the function call yields a delay of approximately 1 1/8 us.
if (–us == 0)
return;
// the following loop takes a quarter of a microsecond (4 cycles)
// per iteration, so execute it four times for each microsecond of
// delay requested.
us <<= 2;
// account for the time taken in the preceeding commands.
us -= 2;
// busy wait
__asm__ __volatile__ (
“1: sbiw %0,1” “\n\t” // 2 cycles
“brne 1b” : “=w” (us) : “0” (us) // 2 cycles
);
}

For Arduino, the 1-wire write operation can be performed with this function:

void OWWrite(uint8_t bit){
if(bit){
//Write bit ‘1’
digitalWrite(PINNUMBER, 0x00);
delayMicroseconds(6);
digitalWrite(PINNUMBER, 0x01);
delayMicroseconds(64);
}
else{
//Write bit ‘0’
digitalWrite(PINNUMBER, 0x00);
delayMicroseconds(60);
digitalWrite(PINNUMBER, 0x01);
delayMicroseconds(10);
}
}

For a computer, the same function can be written in C++, as follows:

void OWWrite(uint8_t bit){
if(bit==1){
//PF5 is port name
PORTF &= ~(1<<PF5);
delayMicroseconds(6);
PORTF |= (1<<PF5);
delayMicroseconds(64);
}
else{
PORTF &= ~(1<<PF5);
delayMicroseconds(60);
PORTF |= (1<<PF5);
delayMicroseconds(10);
}
}

For Arduino, the 1-wire read operation can be performed by this function:

uint8_t OWRead(void){
uint8_t result;
digitalWrite(PINNUMBER, 0x00);
delayMicroseconds(6);
digitalWrite(PINNUMBER, 0x01);
delayMicroseconds(9);
pinMode(PINNUMBER, INPUT);
result = digitalRead(PINNUMBER) & 0x01;
delayMicroseconds(55);
pinMode(PINNUMBER, OUTPUT);
return result;
}

For a computer, the same function can be written in C++ as following.

uint8_t OWReadBit(void){
uint8_t result = 0;
PORTF &= ~(1<<PF5);
delayMicroseconds(10);
PORTF |= (1<<PF5);
delayMicroseconds(20);
if(PINF & (1<<PF5)){
result = HIGH;
}
delayMicroseconds(30);
return result;
}

For Arduino, the reset and presence operation can be performed using this function:

uint8_t OWResetPresence(void){
uint8_t result;
delayMicroseconds(0);
digitalWrite(PINNUMBER, 0x00);
delayMicroseconds(480);
digitalWrite(PINNUMBER, 0x01);
delayMicroseconds(70);
pinMode(PINNUMBER, INPUT);
result = digitalRead(PINNUMBER)^0x01;
delayMicroseconds(410);
pinMode(PINNUMBER, OUTPUT);
return result;
}

For a computer, the same function can be written in C++:

uint8_t OWResetPresence(void){
uint8_t result = LOW;
PORTF &= ~(1<<PF5);
delayMicroseconds(480);
PORTF |= (1<<PF5);
delayMicroseconds(55);
if(PINF&(1<<PF5)){
result = HIGH;
}
return result;
}

Microcontrollers and computers can use the UART for the interrupt-driven implementation of the 1-Wire protocol. Computers might need an external UART chip or breakout board for communicating with 1-wire devices.

The UART’s Tx and Rx must connect to the data line of the 1-wire bus. The UART port must have an open-collector buffer so that the slave(s) can pull down the data line. For the reset and presence signal, the baud rate must be set to 9600, and the controller/computer needs to transmit 0xF0.

During transmission:

  • Bits 0~3 are set to ‘0’
  • Bit 4 is set to ‘1’
  • Bits 5~7 are written by the slave.
  • The stop bit is set HIGH

If there’s no slave connected to the bus, the received value is 0xF0. If any value other than 0xF0 is received, it indicates the presence of a 1-wire slave(s) on the bus.

For a 1-wire write operation, the UART’s baud rate must be set to 115200. The start bit must be set to ‘0’ and the stop bit to ‘1.’

To write ‘1,’ the UART must transmit 0xFF and receive 0xFF in return. To write ‘0,’ the UART must transmit 0x00 and receive 0x00 in return.

For a 1-wire read operation, the UART’s baud rate must be set to 115200. The start bit must be set to ‘0’ and the stop bit to ‘1.’ To read, the UART transmits a value of 0xFF, which is equivalent to releasing the line pulled in a HIGH state. The rest of the bits are written by the slave. If a slave writes ‘1,’ all the bits after the start bit are set to ‘1,’ so the UART receives a value of 0xFF. If a slave writes ‘0,’ all the bits after the start bit are set to ‘0,’ so the UART receives any value other than 0xFF.

What is the 1-Wire protocol? (7)

Sequence detection
The master device can search and detect any arbitrary number of 1-wire slave devices on the bus. It’s also possible to connect up to 100 slave devices to a 1-wire standard bus. However, in a standard 1-wire bus, the master has no mechanism to detect the physical sequence of the slave devices over the bus. And in some 1-wire devices, two additional pins are provided to support the sequence detection. One such device is DS28EA00.

What is the 1-Wire protocol? (8)

Sequence detection in 1-wire interface.

Devices
The 1-Wire protocol is a proprietary standard. All the 1-wire devices are manufactured by Maxim Integrated. Some of the notable 1-wire devices are listed in this table.

What is the 1-Wire protocol? (9)

You may also like:

  • Arduino compatible coding 01: Arduino MCU family
  • Arduino compatible coding 02: Getting started with Arduino
  • How does LoRa modulation enable long-range communication?
  • MicroPython: Serial data communication in ESP8266 and ESP32 using UART
  • Understanding the basics of MicroPython programming
  • How to use interrupts with Arduino

Filed Under: Arduino, AVR, Electronic Projects, Tutorials
Tagged With: 1wire, Arduino, avr, bus, communicationbus, conventional, parasitic, pic, powermode, standardbus

What is the 1-Wire protocol? (2024)
Top Articles
Darwin's Game Wiki
District 196 Lunch Menu
Evil Dead Movies In Order & Timeline
Whas Golf Card
Metra Union Pacific West Schedule
What happened to Lori Petty? What is she doing today? Wiki
Phone Number For Walmart Automotive Department
Exam With A Social Studies Section Crossword
Farmers Branch Isd Calendar
Craigslist Dog Sitter
Canelo Vs Ryder Directv
Braums Pay Per Hour
Matthew Rotuno Johnson
Craigslist Malone New York
Rams vs. Lions highlights: Detroit defeats Los Angeles 26-20 in overtime thriller
All Obituaries | Buie's Funeral Home | Raeford NC funeral home and cremation
Aldine Isd Pay Scale 23-24
Army Oubs
Sni 35 Wiring Diagram
Missouri Highway Patrol Crash
Myhr North Memorial
Craigslist St. Cloud Minnesota
Stihl Dealer Albuquerque
پنل کاربری سایت همسریابی هلو
Telegram Voyeur
Random Bibleizer
Danielle Ranslow Obituary
Gesichtspflege & Gesichtscreme
Ts Modesto
Nikki Catsouras: The Tragic Story Behind The Face And Body Images
A Plus Nails Stewartville Mn
Ancestors The Humankind Odyssey Wikia
Calculator Souo
Flixtor Nu Not Working
How to Get Into UCLA: Admissions Stats + Tips
Car Crash On 5 Freeway Today
Studio 22 Nashville Review
Myql Loan Login
Convenient Care Palmer Ma
Sept Month Weather
The best bagels in NYC, according to a New Yorker
Achieving and Maintaining 10% Body Fat
At Home Hourly Pay
Saline Inmate Roster
Walgreens On Secor And Alexis
Powerspec G512
LumiSpa iO Activating Cleanser kaufen | 19% Rabatt | NuSkin
Anonib New
Arnold Swansinger Family
King Fields Mortuary
Bob Wright Yukon Accident
Obituaries in Westchester, NY | The Journal News
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 6016

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.