HAL library 05- OneWire for STM32Fxxx

Next port from STM32F4xx STD drivers to STM32Fxxx HAL drivers was done for OneWire library. This library is protocol based only. It features basic functions for read/write byte, reset port and search devices on OneWire port.

1-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.


Read more about new HAL libraries


  • Read/write byte
  • Search for devices on 1-wire pin
  • Read rom from device
  • Unlimited OneWire ports on STM32Fxxx
      • This allows you to group sensors to separate ports to prevent communication failures if one sensor is broken


  • HAL
  • TM
    • STM32Fxxx HAL
    • defines.h
    • GPIO
    • DELAY

Functions and enumerations

Example 1

Example 2

Project is available on Github, download all libraries below.

TM STM32 Libraries

STM32 libraries based on STM32Fxxx HAL drivers.


Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Pingback: All STM32 HAL libraries - STM32F4 Discovery()

  • Lau

    I need to read data from a DHT11, it uses OneWire to transmit. Can I just use the function ReadByte from your library or do you recommend using the DS18B20 and make some modifications?

    • As you want. Probably this is better to use and make your DHT layer based on this libs for ready byte, reset and so on. Read DHT manual for proper processing.

  • RusikOk

    Hello! could you share a typical wiring diagram for sensor ds18b20 for your library

    • Normal wiring as ds18b20 uses. Pullup on data pin and thats all.

      • RusikOk

        for use with 1-wire used UART?

  • Burak Doğançay

    Hello, Is there anyway to use this library for stm32f030f4p6 ?
    I get many errors when ı tried to do it.

    • There are absolutelly ways to use this lib there.
      Modifications are required to get it to work.

      Saying I get many errors does not give me any info.

  • Lukas

    Did I understand right, that it is possible to use any I/O Pin (so not necessaraly a USART Pin), just hang a 4,7k Pullup to VCC and than I can have severall 1 Wire devices on that line?

    • It was never mentioned about any usart pin. You can use any pin as this lib does not require any peripheral. Everything is done by software.

      • Lukas

        Thanks a lot for your fast answer!! This is perfect, will try to get it running the next days at the STM32-F100 (Old STM Discovery) and Nucleo STM32-F103 🙂

  • riadh

    how to config one-wire using cubemx any solution !

  • Can I use this library to use STM32 as a slave device?

    • No. Onewire is not common for slave on MCU.

      • Big thanks! This library and 18b20 library, support the STM32F0 family ?