cancel
Showing results for 
Search instead for 
Did you mean: 

DS18B20 Sensor Detection via ONE-WIRE (1-Wire) Protocol

Emanuele78
Associate III
Hi, where can I find a working One-Wire protocol? Is there an example provided by STM? I wrote code for a program to detect the temperature from a DS18B20 sensor, but I can’t detect the sensor, even though the debug shows everything is fine. Can someone help me? Thanks
13 REPLIES 13
nimaltd
Senior

Hi. I released new one wire library. It is non-blocking and can run on any pins.

Https://github.com/nimaltd/ow

Andrew Neil
Super User

EDIT: Oops - I missed that this is an old post (nearly a year), which has just been woken up by @nimaltd

So all of this has pretty much been said already:

 

First call should always be to see what the manufacturer says:

Choosing the Right 1-Wire Master for the Embedded Applications

 

Application Note 148: Guidelines for Reliable Long Line 1-Wire® Networks

There is basic, MCU-independent code here:

Interfacing the DS18X20/DS1822 1-Wire® Temperature Sensor in a Microcontroller Environment

 

See also:

https://community.st.com/t5/stm32-mcus-embedded-software/ds18b20-sensor-detection-via-one-wire-1-wire-protocol/m-p/729945/highlight/true#M55860

 


@Emanuele78 wrote:
even though the debug shows everything is fine.

Clearly everything is not fine - it doesn't work!

 

A software debugger probably won't show hardware problems.

Are you sure that the DS18B20 actually works?

Is it wired correctly?

Please show your schematics; some good, clear photos of your setup may also help - see:

How to write your question to maximize your chances to find a solution

 

Have you used an oscilloscope to see what's actually happening on the wire?

The DS18B20 datasheet & links above show what you should be seeing...

 

Note that DS18B20 are commonly faked - are you sure you have a genuine one?

Does it work with any other controller; eg, Arduino?

See:

https://community.st.com/t5/others-stm32-mcus-related/ds18b20-one-works-one-doesn-t-on-stm32l071-both-ok-on-arduino/m-p/833866/highlight/true#M7818


@Emanuele78 Are you still there? Did you fix this?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Yes :) @Andrew Neil 

Because I released a library. It is non-blocking and very simple. And ready to use. I tested with 2 ds18b20 on bus and works perfectly. 

 

Andrew Neil
Super User

Just to collect together some more 1-WireTM tips:

  1. Although the timing within a bit frame is critical, the timing between bits is not.
    So a blocking implementation only really needs to block for each bit - not the whole transaction.
    This also helps debugging - you can still breakpoint between bits.

  2. UART and SPI can be used to "synthesise" the timing.
    See, for example: Using a UART to Implement a 1-Wire Bus Master
    discussed here: Dallas iButton and UART.

#1WireTips

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.