HAL library 06- DS18B20 for STM32Fxxx

When you have onewire library done, it’s easy to make interface for DS18B20 sensors.


Read more about new HAL libraries


  • Search sensors
  • Read temperature
  • Set resolution for each device from 9 to 12 bits
  • Start temperature conversion on all devices simultaneously
  • Set alarm low and high temperatures
  • Disable alarm temperatures
  • Search devices with alarm flag set


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

Functions and enumerations



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()

  • Jędrzej Szczepaniak

    Hi, I have some problem with this library. I’m working on STM32F4-DISCO and can’t find any devices on OneWire line. I created project with STMCubeMX. I’m not sure how to set up pin for OneWire there. Any tips?

    • My guess, delay problems.

      • Jędrzej Szczepaniak

        I’m using TM delay lib. Only I do with them is change include file names. Should I do something more?
        I’m starting with STMs and first time using this libs.

        • Try to run rhis example directly from github project for start and check if it works.

          • Jędrzej Szczepaniak

            I’ve run example from git and it’s working, but I wondering why my project don’t.

          • I see here 2 possible reasons. Oje is that pll is not set correct, second is that delay does not work ok. I think first reason has more chances to win.

          • Jędrzej Szczepaniak

            This is how it look like in my project. There are default values, made by STMCube

          • First of all, hclk should be 168MHz, and source for pll on your board is external 8MHz. Second…why you use stmcubemx? This is source of problems.

          • Jędrzej Szczepaniak

            Heard it is good tool. Why it is problem?

          • As you can see, you have plenty of problems why it is not working.

          • Jędrzej Szczepaniak

            Didn’t expected that Cube cause this problems. But any idea why? There only way is to avoid Cube?

          • CubeMX is still not tool for newbies.

          • Jędrzej Szczepaniak

            OK, many thanks for help. I just donate you for big beer. 🙂

  • Mahmud Ibrahim

    Hi Tilen, how r u? I guess u r doing well. I have some problem with this DS18B20 library of yours. I have tired it with STM32F051 Discovery. Unfortunately, discovery board can’t find any device on One Wire line (PD2). I have used start_up stm32f051 instead of start_up stm32f091. May be i made mistake in PLL setting. Will u please point me the error in the given C/C+ define of keil….


    Secondly, I have also face problem in USART program. The same program u have written, i also tired it. But the problem is some garbage value it’s displaying. I knew its because of baudrate setting. i have set the baud rate at 9600. But i think this problem is also related to PLL setting. The same one above. it would be great if you create a keil setting for STM32F051 discovery.


  • Mert Lama

    Hi Tilen, how can use your ds18b20 lib with stm32f103c8, i have some problem with that

  • Dmitriy Budeukin

    Hi, I want running this example on Nucleo F446RE. Using IAR IDE, connect libs from example. And I have problem with “defines.h”. If someone knows how to find it, help me please.