DS1820 / OneWire library doesn't work on mbedos5, mbedos6 (NUCLEO-F303RE)

As discussed a bit here, the NUCLEO-F303RE has issues when using OneWire. I encountered the same issue when using an STM32F411CE board (the ‘Black Pill’ from WeAct).

The presence of a OneWire device is detected, and the ‘search ROM 0xf0’ command sent, but after that there is no valid activity on the bus. I am mainly using Zoltan Hudak’s DS1820 library but I have also tried Erik’s (worked on mbed2 only) and other libraries (generally: mbed2 worked, mbedos5 or 6 did not).

I have a 4k7 pullup from DATA to VCC. The F303RE does seem capable of the required timing for the GPIO input<->output mode transition. The fault seems to occur at varying stages of sending the identifier bits of the DS18B20:
image

In this picture only 2 bits after were sent, but I have counted as many as ~30 sent. This corresponds to the search portion of the OneWire code. I don’t have any other OneWire devices to test, but it seems to be a problem with the OneWire library and not the DS1820 library.

My DS18B20 sensors are likely clones, but they work with arduino (AVR), esp8266, and the mbed2 libraries.

Hello 大 电,

There is an issue with the online compiler. To check/change the revision right-click on the mbed-os icon in your project and select Revisions.... The currently used revision is listed in bold. Select (click on) the last one (tag: mbed-os 6.2.1) and click on the switch button on the toolbar. Please update the DS1820 library in your project to the latest revision too. Also make sure a pull-up resistor is used as shown here. For additional info have a look at this Mbed OS 6.1+ bug?.

Best regards, Zoltan

Hi Zoltan,

Thank you for your quick and informative reply.

I’ve tried again with mbedos 6.2.1, the latest version of your library, and I already had a 4.7kOhm pullup (the sensor works with my arduino nano). Unfortunately the issue of no activity after the ‘search ROM’ command persists.
However I’ve realized I was using 5.14.2 before, which from what I understand should have already been working with your library without any issues. So it seems like maybe I have a different issue than the previous incompability with mbed 6.

I also tried your DS1820_Hello example and that encountered the same issue.

The DS18B20 I have are clones as identified by this project, could that result in issues when using your library?

edit: After reading through this thread I found this library which has finally given me a working DS18B20 with mbed. That library seems to implement its own search return rather than using the one from the OneWire library - which to me indicates the issue is with the OneWire library and not yours.

edit2: That library sadly also encounters timing issues with mbed os 6. Is the timing on onewire devices really so tight that normal GPIO methods don’t work with RTOS?

Hello 大 电,

Is the timing on onewire devices really so tight that normal GPIO methods don’t work with RTOS?

One-wire timing constrains shouldn’t be a big issue. But, as explained here, a long transition period from digital output to digital input on some ARM targets makes it difficult or even impossible to meet. Wen you are running your code and on the serial terminal you see an error message like:

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: _out_to_in_transition_us < _sample_point_us
...

It indicates that your ARM chip is not capable to reconfigure the used GPIO from output to input in time (default is 13us). You can then try to change the sample point by passing a different value in the constructor.
For example:

DS1820  ds1820(D8, 15);  // sample point set to 15 us

Although in some cases (e.g. fake sensors) it could help to shorten the sampling point below 13us.

Best regards, Zoltan

Hi Zoltan,

I’ve tried a few different delay times: 7, 10, 13, 15, 30, 50, 100. I got the assertion error for 7us only. “No DS1820 sensor found” in all cases.

Nucleo F303RE, mbedos 6.2.1, and your library version from 2020-07-20 in the online compiler.

Can you give any known-good setups? eg a specific board, mbed version, library version, and method of development (online/mbed studio/etc).

Hello 大 电,

The NUCLEO-F303RE seems to be fast enough for 1-wire :slight_smile: . Could you please post some debug messages? In the DS1820.cpp file replace

#define DEBUG 0

with

#define DEBUG 1

Thank you.

Hi Zoltan,

This was the output:

lastAddr = 0 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 28 4 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 4 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 0 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 8 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 4 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 18 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 1 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 8 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 28 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 8 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 28 b0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 2 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 1 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 4 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 4 0 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!
lastAddr = 28 4 0 0 0 0 0 0
No addresses.
No DS1820 sensor found!

Often all 0s, sometimes some value in the first column, less often a value in the second column too, even less often a value in the third column. Waiting long enough I saw one lastAddr getting to 5 non-zero columns.
Looking at a few of the events with a logic analyzer, the amount of bits after the ‘search ROM’ command varies from about 2 - 25.

Ahoj,

Nucleo-F303RE + MbedOS 6.2.1 + DS18B20 (4k7) + Zoltan’s DS1820 and it is working.
I cut out only the Serial object, changed its printf to console printf and set the printf_minimal to std.

BR, Jan

Hello Jan,

Thank you for sharing your working configuration. It’s good to know that the F303RE specifically doesn’t have a problem. Do you know if your DS18B20 is from a known authentic source? (eg not aliexpress or ebay).

I recreated the exact same configuration as yours but could not get my DS18B20 detected. As I said before I did get it to work with an old mbed2 example program, so I will try to find the approximate version of mbedos that the library stopped working for my clone ds18b20.

I think for my own sanity I will soon switch to using I2C sensor modules like mcp9808 that are a bit more expensive but simply work.

Hello,

I have sensors from the Ali and also from the Mouser or the Farnell, I think.
I will try to check it, test it and come back to you later (I hope today/tomorrow).

BR, Jan

Ok, checked my components and they all look like copies (I checked my order histories and I only bought from the Ali…). I tested 3 different and all are working.
BR, Jan

Thanks for checking! Looks like it really should work without issue for me as well.

There’s a lot of variance in the copies (see GitHub - cpetrich/counterfeit_DS18B20: How to tell original from fake DS18B20 temperature sensors.) and mine are the worst ones (Family D2) so it’s certainly possible I have a particularly dubious clone that runs into issues. I think I have one waterproof one from family B2, I will have to see if that one encounters the same issues.

My DS18B20 sensors are likely clones, but they work with arduino (AVR), esp8266, and the mbed2 libraries.

Which arduino (AVR) library did you use? Could you please provide a link? I can try to modify/extend the ROM search algorithm to work also with this type of clones.

Hi Zoltan,

I use the DallasTemperature library: GitHub - milesburton/Arduino-Temperature-Control-Library: Arduino Temperature Library
Which in turn uses this OneWire library: GitHub - PaulStoffregen/OneWire: Library for Dallas/Maxim 1-Wire Chips

I just tried my waterproof family B2 DS18B20 clone and it works with your library and mbedos 6.2.1! So that’s at least one sensor I can use.

edit: I decided to test all of the unsoldered family D2 clones I have (six) in one go in a breadboard with your multiple sensors example. Surprisingly, every single one was detected! All with accurate temperatures within about a 1C range. So then I removed one at a time and reset my nucleo each time:

  • 6 sensors, all detected
  • 5 sensors, all detected
  • 4 sensors, only one detected
  • 3 sensors, none detected (same issue as before, the search fails)
  • 2 sensors, none detected
  • 1 sensor, not detected

I added them back randomly 1 at a time and the same behaviour was obseved.

This was with one 4.7k pullup to 3.3v.

I have no idea how to even interpret this behaviour. I assume there must be some kind of electrical effect happening from adding each ds18b20? Like extra capacitance or resistance? The resistance to Vcc (4.7k from the resistor) and to ground (14k, I assume from effects internal to the ds18b20 and stm32) didn’t change much by adding or removing sensors.

edit2:
With a 20kOhm resistor instead of 4.7k I can now detect individual DS18B20!
I guess these clones are possibly not so good at sinking current, which causes issues with some libraries but not others depending on speed?

Hi Kuutei 大 电, how do you use that Arduino libraries in Mbed?

Could you share an example?

Thank you.

Hi Johnny,

In that post I was talking about the libraries I was using with my Arduinos.

To my knowledge the only way to use an Arduino library in mbed is to rewrite it to use the mbed GPIO functions, play nice with the RTOS, etc.

It seems the Arduino foundation wrote Arduino on top of Mbed for the Nano 33 IoT, however I have no idea how they did that.

Hi there,
just to let you know that also depending on compilation mode (Release ot not) may affect reading. For example, on STM32WL Release mode it does not work, check this issue
May be the definitive solution is to switch to UART mode at cost of one serial and not available on all pins.

1 Like