Library 12- OneWire library for STM32F4

onewire devices1-Wire is a device communications bus system designed by Dallas Semiconductor Corp. that provides low-speed data, signaling, and power over a single signal.

It’s used in some temperature sensors, like DS18B20 temp sensor and many others products from Dallas.

OneWire key features

  • Single Contact Sufficient for Control and Operation
  • Unique ID Factory-Lasered in Each Device
  • Power Derived from Signal Bus (“Parasitically Powered”)
  • Multidrop Capable: Supports Multiple Devices on Single Line
  • Exceptional ESD Performance


17th May, 2014: There was some new functions added!



  • Read/write byte
  • Search for devices on 1-wire pin
  • Read rom from device
  • Version 2.0 – January 04, 2015
    • Library rewritten
    • It supports unlimited pins and gpios for OneWire
    • This allows you to group sensors to separate ports to prevent communication failures if one sensor is broken
  • Version 2.1 – March 10, 2015
    • Supported new GPIO system


    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
  • TM
    • TM DELAY
    • TO GPIO
    • defines.h
    • attributes.h


Before you can work with 1-wire bus, you have to initialize it

Reset pulse

If you need to reset 1-wire bus, simple call reset function

Write byte

Read byte

Search devices

Select device

Because you have more devices on one line, you have to somehow select device which you want to communicate with. You can do this with

Functions and enumerations


I connected 2 DS18B20 sensors to PD0 (make sure, you have external pullup resistor) and this code returns me on terminal.

One Wire devices connected to STM32F4

One Wire devices connected to STM32F4

Example 2

  • 4 devices are connected to STM32F4 via OneWire:
  • 2 OneWire ports:
    • PA3
    • PD0
OneWire example with multi instances

OneWire example with multi instances

Projects available on Github, download library below.


Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...