Using 1-wire devices

The 1-wire is a serial interface which is only using one wire (plus the ground) to transmit data between a microcontroller and a 1-wire component. Moreover, the power supply of the 1-wire component can be drawn by the serial interface itself, making the 1-wire a very interesting communication link to connect various components to a microcontroller. A lot of components using 1-wire are available today: RTC, memories, sensors...

This application note shows how to simply connect 1-wire devices to a microcontroller. It uses a DS18B20 temperature sensor.

You can download the full article and source codes using the following link:

Using 1-wire devices - Revision 1.2, 2012-07-31

1. Schematic

The 1-wire device is connected to the microcontroller using two simple resistors, has shown on the following schematic.

The pull-up resistor R1 is used to power the sensor. The microcontroller will also be used to draw current during temperature conversion. R2 is added to limit the current in case of shortcut on the 1-wire device.

2. Software architecture

The software architecture is shown below.

The 1-wire interface contains low level functions used to communicate with the 1-wire device. Those functions are basic functions which can be used to interface any 1-wire component to the microcontroller, and not only temperature sensors.

DS18B20 interface contains specific functions to use the DS18B20 device. It uses the 1-wire functions to communicate on the 1-wire interface.

Finally, the application is simply using the DS18B20 functions to get the current temperature.

3. User application architecture

The DS18B20 header file must be included in the user application:

#include "ds18b20.h"

The DS18B20 interface contains three functions:

- DS18B20_Init() to initialize the sensor;
- DS18B20_ConvertT() to initiate temperature conversion;
- DS18B20_ReadT() to read the temperature.

Those functions are called according to the following schema.

4. Configuration

The hardware configuration (pin used to connect the sensor) is defined in the 1-wire low level interface. It can be modified in order to match the board requirements.

In the project attached to this application note, the pin which is used to connect the sensor is PTE3:


If you modify the pin, please modify both registers in the above definitions.


This application note shows how to simply connect a 1-wire device on a microcontroller. The standard 1-wire interface files can be used to communicate with any 1-wire component.

The complete documentation attached to this article gives some additionnal details and proposes another possible implementation to add multiple 1-wire devices on the same microcontroller.