5 years, 6 months ago.

Detection problem of a DS1820 on a NUCLEO-L152RE

Hello, I'm having a problem using a DS18B20 sensor. I'm using it on a NUCLEO-L152RE, and i'm trying to get the temperature. I have tried connecting it on the data pin D0 to D7 and A0 to A5, but everytime it's connected i get on debug : "Found 0 device Pinmap error: wrong port number" but if i disconnected the sensor, the program find one device that return "-0.3°C", and if I connect the sensor then, it return "-1000.0°C". A little cold for the season. Do you know what can be causing it, and way to solve it? Thank you

Question relating to:

UPDATE here so people see it:

Specifically for STM devices I switched the library from push pull when possible, to always OpenDrain mode. This works around their slow GPIO input/output switching. Sadly setting it to OpenDrain mode doesn't actually do anything, so I also added a temp workaround which does properly enable OpenDrain mode. The TL;DR is that it should work now. If not let me know.

posted by Erik - 08 Jan 2017

7 Answers

5 years ago.

The problem with ds1820 and Nucleo-L152RE still exist. I check some libraries, olds mbeds etc and find that only https://developer.mbed.org/users/Sissors/code/DS1820/ works (with some little changes ). Any idea to use the "normal" DS1820 library?

That should be the normal DS1820 library, at least the one linked in the component page. I updated it to work around the STM problems (multiple ones). Which other modifications did you need to do?

In general I wouldn't bother to search further, unless it is a library specifically made for STM: They simply have bugs and inefficiencies in their mbed library which will prevent any general library without STM workarounds to work reliably.

posted by Erik - 13 Jan 2017
3 years, 10 months ago.

Hello, I am using the Nucleo-L432KC and I have the same problem "Found 0 device Pinmap error: wrong port number". Can anybody help me? Thanks

5 years, 5 months ago.

I am also getting the same issue? any solution?

5 years, 5 months ago.

It could possibly be because STM32s are (last time I checked) pretty badly programmed to switch pins between input and output. Maybe reducing some timings when it does this in the code could help, but I am not sure. However I can't think of easier ways to fix that. Replacing it completely with FastIO library should do the job, but that is also quite some effort.

You can try one of the other libs, although I expect the same issue.

Hello, The Ds18b20 on Stm32f103c8t6 not work on new mbed stm library. :(

posted by Kiraly Stefan Istvan 06 Jan 2017

I know. I might implement workaround in the library itself, but it is because the mbed STM code for switching GPIOs from input to output is really, really, slow.

posted by Erik - 06 Jan 2017

It should work now.

posted by Erik - 08 Jan 2017
5 years, 2 months ago.

I have a Nucleo L073RZ, and I have the same problem, it doesn't find any devices, and now I'm trying with the DS1820_HelloWorld library, but it says "Pinmap error: wrong port number.Found 0 device(s)"

Any Ideas?

Hi, it all works if you use the mbed library in the example... as soon as you update mbed, it fails.. 'thats on the STM32F072 processor...'

posted by Nick Marsh 14 Nov 2016

Hi, Thanks for your reply I have tried the library in the example but it doesn't compile because of the device.h. I'm running out of ideas

posted by Javier Sing 14 Nov 2016

I can see if I can today or at least coming days give you a modified mbed lib that I think should do the job, but no guarantees.

By the way that Port error you get is not from the DS1820 code, it is from the mbed code. Which pin are you using? Since the only way I know of to get it for your target is by supplying 'NC' as pinname, and then it won't work.

posted by Erik - 16 Nov 2016

Hello, I solved the problem using your FastIO library on another example Thanks for your time

posted by Javier Sing 21 Nov 2016
5 years, 4 months ago.

Hi guys,

The DS1820_HelloWorld works perfectly o the STM32F processor, displaying 20.1C...

However, when the new MBED library is imported, it does not compile.

#define DATA_PIN        PA_4

//#include "mbed.h"
#include "DS1820.h"

//#define ESC 0x1B

#define MAX_PROBES      1
DS1820* probe[MAX_PROBES];

int main()

    Usart1.baud(115200);    // Console through the USB serial port on COM 2 and Rs232 on Connector P4 pins 8 Tx1 and 1 Rx1

    PWM2.period(0.03f);   //Staggered PWM outputs

    int num_devices = 0;
    while(DS1820::unassignedProbe(DATA_PIN)) {
        probe[num_devices] = new DS1820(DATA_PIN);
        if (num_devices == MAX_PROBES)
    Usart1.printf("Found %d device(s)\r\n\n", num_devices);
    while(1) {
        probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        for (int i = 0; i<num_devices; i++)
            Usart1.printf("Device %d returns %3.1foC\r\n", i, probe[i]->temperature());

Error: Expected a ")" in "main.cpp", Line: 36, Col: 39 Error: Expected an expression in "main.cpp", Line: 36, Col: 43

In what you copied you for sure missed a closing '}' at line 42.

posted by Erik - 04 Sep 2016

work ds18b20 on stm32f103rb new mbed library? thanks!

posted by Kiraly Stefan Istvan 06 Jan 2017
5 years, 2 months ago.

Hello, One the NUCLEO-103RB problems:

Found 1 device(s) Device 0 returns -0.30C


Well it does find one device, maybe it is just really cold :P.

I have a possible solution, however since I don't have these myself anymore (I think), I can't really know if it is an actual solution. If you want I can send you in the weekend a modified mbed lib you can try?

posted by Erik - 18 Nov 2016

Hi guys,

don't forget that most on the EBAY style DS1820 sensors, only work on parasitic power...

and I found they only work with the old mbed library.

but I haven't tried the new mbed lib for a few months.

Kiraly, did you load example code from the mbed website ? which one ?

posted by Nick Marsh 19 Nov 2016

FYI I spend some time modifying the mbed lib (more than it should cost, I probably did something wrong the first attempt), and now it works on my F030. Conclusion: The cause seems to be the mbed code to switch between input and output on STM devices. I made a bug report: https://github.com/ARMmbed/mbed-os/issues/3299

posted by Erik - 19 Nov 2016


posted by Kiraly Stefan Istvan 21 Nov 2016

The problems resolve Zoltan Hudak Thank you! DS18B20 work perfect in new mbed library on STM32f103C8t6 https://developer.mbed.org/users/hudakz/code/STM32F103C8T6_DS1820/rev/93ec3038c226

posted by Kiraly Stefan Istvan 08 Jan 2017