OneWire with DS18B20

Post Reply
Posts: 1
Joined: Wed Aug 11, 2021 5:54 am

OneWire with DS18B20

Post by kiloWATT21 »


i'm using a board with STM32L051K8, and i'm having trouble reading temperature from DS18B20.
I have tried all kinds of libraries and codes without the library, but non of it seems to work.
Is the L0 chips just too slow for OneWire protocol. Do i have to use the solution using USART solution with the diode ( )?
User avatar
Posts: 1793
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 96
Location: Le Mans

Re: OneWire with DS18B20

Post by fpiSTM »

Hi @kiloWATT21

if you use the STM32 core then simply use this library:
Posts: 1741
Joined: Thu Dec 19, 2019 5:30 am
Answers: 27

Re: OneWire with DS18B20

Post by ag123 »

many libraries may not work 'out of the box' if they use atmega specific features e.g. hardware timers ... ino-9cc806 ... -tutorial/

what can be done is to review the codes and adapt/port it across to use stm32timers
examples for using the stm32 hardware timer are here (STM core) ... er-library

it is quite easy once you get used to using the stm32 hardware timers, basically 'bit bang' the signals on a port.
you won't need a uart for it as the signals are pretty much 'slow' > 10us.
try the blink examples with stm32 hardware timers to figure out how to control duration, duty cycle, interrupt callback etc

hardware timer codes looks mostly like this

Code: Select all

HardwareTimer *Tim1 = new HardwareTimer(TIM1); 

void Update_IT_callback() {
	//timer calls this every period
	//e.g. digitalWrite(pin), digitalRead(pin);

void setup() {
	Tim1->setMode(channel, TIMER_OUTPUT_COMPARE_PWM1);
	Tim1->setOverflow(10, MICROSEC_FORMAT); // 10 microseconds

void loop() {
	// other sketch codes goes here
	// you can still pause(), refresh(), resume() the timer from here
	// the connection between here and the timer callback is to use global variables or arrays
	// use a global variable to manage state
Post Reply

Return to “STM32L0 based boards”