O que é o protocolo de 1 fio?

What is 1-wire protocol?

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

A 1-wire standard has a master and slave configuration, where there can only be one master device, one computer or microcontroller, and multiple slave devices. It is possible to connect up to 100 1-wire slave devices, with a standard 1-wire bus. However, as slave devices are added to the bus, their search for the master device may take longer.

This protocol does not use a clock signal. Instead, slave devices are synchronized internally 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 on the bus when the master is reset. Each master device is identified by a 64-bit address, stored in the ROM of each one-wire slave device.

This is a low-speed serial communication standard, with a typical data speed of 15.4 kbps. The bus can be overloaded up to a maximum data speed of 125 kbps. Data speeds in the 1-wire protocol are low compared to other standard serial data communications protocols (such as UART, I2C, and SPI), but the 1-wire bus is extremely economical to produce and operate. It offers simple hardware implementation and extremely low power consumption.

Although the hardware is simple, the software implementation on the microcontroller side is highly complex. And despite its 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 is now) Maxim Integrated.

Let's discuss in more detail.

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

The standard 1-wire bus
The standard 1-wire bus has at least two wires. One is the data line and the other is the ground return. Both the master and slaves have an open drain (open collector) connection to the data line. This is why a 4.7K resistor typically pulls the data line. There are two possible power modes for 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 conventional power mode is used, an additional positive power line must be drawn for each 1-wire slave connected to the bus.

Therefore, the 1-wire bus on a PCB can have two or three lines. Conventional power with three lines on the 1-wire bus is more reliable.

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

Slave devices have an internal 800 pF capacitor, which is charged when the data line is HIGH. The stored charge keeps the slave active when the data line is LOW. The data line is typically pulled through a 4.7K resistor.

Parasitic power requires strict timing and supply to exact specifications to keep the slave device active without failure. This is why this mode is less reliable. Often an additional hard pull-up is used to check the power supply.

Parasitic power from 1-wire devices.

Parasitic power supply for 1-wire devices with an additional hard pull-up.

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

Conventional power supply for 1-wire devices.

Typical 1-wire devices operate at voltages of – 1.71 ~ 1.89 V, 1.71 ~ 3.63 V, 2.97 ~ 6.63 V and 2.97 ~ 5.25 V. Current drawn varies between 1.06~5mA. The pull-up resistor sets the current level regardless of whether the devices receive parasitic or conventional power.

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

Communication over the data line is initiated by the master through a reset. It pulls the data line to 480 knots 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 knots. If the line is pulled by the slave(s), the master confirms its presence on the bus. After 60~240 nodes, the slave(s) release the data line, so that the master can start writing.

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

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

As the 1-Wire standard does not use any clock signal, the communication of bits '0' and '1' occurs by configuring the logical level of the data line for a specific time interval. Typically, the time range is 60 knots. There is also a 1us gap between each time interval so that the data line is pulled HIGH again by the pull-up resistor. During each 60 us time interval, 1 bit is communicated between the master and slave. The time interval can be up to 10 times shorter if the bus is overloaded.

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

  • To write '0', the master pulls the data line for the full 60 us time interval and then flushes it for a 1 us interval between time intervals.
  • To write '1', the master pulls the data line down for a shorter period of 15 us, throughout the time interval, and then releases it for a 1us interval between time intervals.

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

The master reads from the slave device after sending a ROM poll or function command. The reading operation is controlled by the master device. The master reads the slave bit by bit while data is communicated to the master in groups of 8 bits. Each bit is read in a time interval of 60 us (or less if the bus is overloaded).

The master pulls the data line to 1 nodes and releases it. It then samples the bus data after 15 nodes. If the slave writes '0' to the bus, it keeps the line pulled down for the 60 us time interval and then flushes the data line for a 1 us interval between time intervals. If the slave writes '1' to the bus, it keeps the line pulled low for 15 knots and then releases the data line to the pull-up resistor to pull the data line HIGH.

The master samples each bit after 15 nodes. If the bit sent by the slave is '0', the line will be pulled LOW at the time of sampling. If the bit sent by the slave is '1', the line will be pulled HIGH at the time of sampling.

The master can communicate with up to 100 slaves on a standard 1-wire bus. However, the greater the number of 1-wire slaves connected to the bus, the longer the master will need to extract data from them. Software libraries typically use bit-banging or 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 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: polling implementation and interrupt-driven implementation. Polled is a software-only implementation. Interrupt-oriented implementation requires an integrated timer/counter.

In terms of Arduino, the researched 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) provides longer than desired delays.
//delay_us(us);
// for the 16 MHz clock on most Arduino boards
// for a one microsecond delay, simply return. the overload
// of the function call produces a delay of approximately 1 1/8 us.
if (–us == 0)
turn back;
// the following loop takes a quarter of a microsecond (4 cycles)
// per iteration, then run it four times for every microsecond of
// requested delay.
nodes <<= 2;
// counts the time spent on previous commands.
nodes -= 2;
//busy wait
__asm__ __volatile__ (
“1: sbiw %0,1” “\n\t” // 2 cycles
“brne 1b”: “=w” (us): “0” (us) // 2 cycles
);
}

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

void OWWrite(uint8_t bit){
if(bit){
//Write bit '1'
digitalWrite(PIN NUMBER, 0x00);
delayMicroseconds(6);
digitalWrite(PIN NUMBER, 0x01);
delayMicroseconds(64);
}
other{
//Write bit '0'
digitalWrite(PIN NUMBER, 0x00);
delayMicroseconds(60);
digitalWrite(PIN NUMBER, 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 the port name
PORTF &= ~(1<
delayMicroseconds(6);
PORTF = (1<

delayMicroseconds(64);
}
other{
PORTF &= ~(1<

delayMicroseconds(60);
PORTF = (1<
delayMicroseconds(10);
}
}

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

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

pinMode(PIN NUMBER, OUTPUT);
return result;
}

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

uint8_t OWReadBit(void){
result uint8_t = 0;
PORTF &= ~(1<
delayMicroseconds(10);
PORTF = (1<

delayMicroseconds(20);
if(PINF&(1<

result = HIGH;
}
delayMicroseconds(30);
return result;
}

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

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

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

uint8_t OWResetPresence(void){
result uint8_t = LOW;
PORTF &= ~(1<
delayMicroseconds(480);
PORTF = (1<

delayMicroseconds(55);
if(PINF&(1<

result = HIGH;
}
return result;
}

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

The Tx and Rx of the UART must connect to the 1-wire bus data line. The UART port must have an open collector buffer so that the slave(s) can pull 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 to 7 are written by the slave.
  • Stop bit is set to HIGH

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

For a 1-wire write operation, the UART 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 baud rate of the UART 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 0xFF, which is equivalent to releasing the pulled line in the HIGH state. The rest of the bits are written by the slave. If a slave writes '1', all bits after the start bit will be set to '1', so the UART will receive a value of 0xFF. If a slave writes '0', all bits after the start bit will be set to '0', so the UART will receive any value other than 0xFF.

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

Sequence detection on 1-wire interface.

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

Conteúdo Relacionado

How to Troubleshoot Common ESP32-CAM Problems
ESP32-CAM is a compact camera module that combines the...
What is the role of automotive sensors in modern vehicles?
A network of sensors is embedded in every vehicle,...
How to choose an e-bike controller
The motor controller is one of the most important...
A guide to USB standards from 1.0 to USB4
A evolução dos padrões USB foi fundamental para moldar...
Schurter aprimora série de seletores de tensão com revestimento prateado
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A interface serial PCI fornece conectividade confiável em ambientes extremos
A Sealevel Systems anuncia o lançamento da Interface Serial...
STMicroelectronics expande portfólio de conversão de energia com diodos Trench Schottky de 100 V
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
O que são Sistemas Globais de Navegação por Satélite (GNSS) e como são usados?
Determinar uma localização precisa é necessário em várias indústrias...
O conversor GaN de 50 W da STMicroelectronics permite projetos de energia de alta eficiência
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
Samsung e Red Hat farão parceria em software de memória de próxima geração
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
Primeiro MPU single-core com interface de câmera MIPI CSI-2 e áudio
O mercado embarcado tem uma necessidade de soluções de...
Fluency decoding in induction motor for better performance
You have probably come across the term ' drag...
Understanding Support Insulators in Electrical Systems
You probably have a support insulator if you've noticed...
Explore Stay Insulator – safety, installation and maintenance
You've probably seen stand an insulator sit on power...
More safety and efficiency with the shackle isolator
You've probably seen shackle insulators enthroned on electricity poles,...
Discover the power of latching relays for energy efficiency and more
You have probably experienced situations where controlling a circuit...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.