1 month ago.

Detection of tempertaure sensor DS1820 on a STM DISCO-L072CZ-LRWAN1

Hi, I have some issue with detecting this sensor. I tryed different libraries:

I had a long research about, and seems that the problem is on the MBED library for I/O on STM board since it is slow in changing between read and write mode on the single (One Wire) Digital pin of the sensor.

I found that a possible solution is to try increasing or decrising the time in the reading function in the library for DS1820, but for me did not work. I also found that is possible to replace the mbed library for IO with FASTIO : But unfortunately did not work out. Someone else, that maybe is facing my same problem, could help me? Thanks

Comment on this question

2 Answers

1 month ago.

Hello, Enrico

Give this library one more try. The right sampling moment is now calculated based on the time needed to change the GPIO from output to input.

Zoltan, your library is not working on all targets, just tried it on K22F using MBED-DEV rev. 187.

No DS1820 sensor found!

Reloaded Erik's library using the same hardware, it is working, but nothing works on the STM32L152.

Some quick checks, L476, F401, F446. LPC1768, K64F are working.


The L152 does work on MBED-DEV rev.177

I'm beginning to think that most of the MBED libraries are now so fragmented it would probably quicker to delete the lot and start over again.

posted by Paul Staron 20 Jan 2019

Hi Zoltan, thank you so much for your answer, I'm getting crazy with this board.... I tryed the library that you suggested me on a new OS 5 project and as main.cpp the example that you suggest in your library.

But now the execution of the "main" function starts and then get stuck giving no output about the presence or not of the DS1820 sensor.

Have you ever had a issue like that?

Thank you

posted by Enrico Verz 20 Jan 2019

Sorry guys, but it works fine on all my boards (LPC1768, NUCLEO-103RB, NUCLEO-F446RE and STM32F407VET6) using the online compiler and the latest Mbed OS2 library. Could you please run the following test program and let me know the printout.

#include "mbed.h"

DigitalInOut    line(PA_10);
Timer           timer;

int main()
    printf("delay1 = %dus\r\n", timer.read_us());
    printf("delay2 = %dus\r\n", timer.read_us());

    while (true) { }
posted by Zoltan Hudak 20 Jan 2019

I tryed your code creating a new project:

$mbed new mbed-classic mbedlib

$mbed remove mbed

$mbed add

$mbed compile -t GCC_ARM -m DISCO_L072CZ_LRWAN1

The output is just: " delay1 = 17us delay2 = 13us " Does not matter if the sensor is connected or not, se response is always the same.

posted by Enrico Verz 20 Jan 2019

That's beyond the 15us limit required by 1-wire signalling for read slots. So I improved the library by using only output configured as open draing for reading bits when STM boards are used (an approach used by Erik Olieman in the library.

posted by Zoltan Hudak 21 Jan 2019

STM boards are very slow when it comes to swtiching a GPIO pin from output to input. Specifically on DISCO-L072CZ-LRWAN1 it takes about 17 us (see above the results of your test). Because that's more than the maximum time allowed for a read time slot in 1-wire signallig (15 us) I think it's impossible to design a realiable read-bit function for your board using mbed's high level functions. In hope that it could cut 1 or 2 us I have tried to optimize the library for STM boards by using lower level functions. Please let me know how it works now.

posted by Zoltan Hudak 26 Jan 2019
4 weeks ago.

I try this library with NUCLEO-L476RG board and works wrong. My app try 3 times with 1s delay after each try to detect sensor, but I must reset 5-10 times Nucleo board so that the sensor can be detected. But even if sensor is detected, I can read temperature only about 1 in 20-30 attempts due to CRC errors.

To post an answer, please log in.