Skip to main content
Associate
August 26, 2025
Question

DS18B20: one works, one doesn’t on STM32L071 (both OK on Arduino)

  • August 26, 2025
  • 2 replies
  • 548 views

TL;DR: Two “DS18B20” sensors both work on Arduino, but on my STM32L071xx board only one works; the other never responds. I’m generating 1 µs delays from a 32 MHz clock. Suspecting clone/timing or power-mode differences. Looking for gotchas others have hit on STM32/1-Wire.

Context / setup

  • MCU: STM32L071xx, 3.3 V logic

  • Bus: single DS18B20 per test (no multi-drop)

  • Pull-up: 4.7 kΩ to 3.3 V (external)

  • Wiring length: 50 cm

  • Power mode: 3-wire

  • Timing: delays built from 32 MHz system clock, 1 µs granularity (busy-wait / timer)

What I see

  • Arduino (5 V): both sensors enumerate, convert, and read fine.

  • STM32L071 (3.3 V): Sensor A works flawlessly; Sensor B shows no presence pulse / no ROM code (or occasionally garbage/CRC fail, depending on timing tweaks).

What I’ve tried

  • Verified wiring continuity and pinout (DATA/VDD/GND).

  • Switched the STM32 GPIO to open-drain, high-speed; internal pulls disabled.

  • Tried stronger pull-ups (3.3 kΩ / 2.2 kΩ).

  • Stretched/relaxed timings around spec:

    • Reset low: ~520 µs, sample presence at ~70–80 µs after release

    • Write ‘1’: low 6–10 µs, slot ≥60 µs

    • Write ‘0’: low ~60 µs

    • Read: low 2–5 µs, sample at ~12–18 µs, slot ≥60 µs

  • Confirmed idle bus sits at 3.3 V.

I'm really stuck here, and tempted to buy an extra official DS18B20 probe to test my hypothesis.

Any Advice apreciated :)

I can share my code if wanted but i followed this tutorial. (only diffrence is clock speed, but that shouldn't matter)

 

2 replies

Associate II
August 26, 2025

Hi Jevil,

 

DS18B20 are known to be faked frequently.

Before wasting much time I would buy some from a reliable source.

 

BR Klaus

Andrew Neil
Super User
August 26, 2025

@mfgkw wrote:

DS18B20 are known to be faked frequently.


Indeed.

Although, if they work with an Arduino, they should work with any other microcontroller: the sensor - even a fake/clone - isn't sensitive to different make & models of microcontroller!

However, it is possible that the specs are different - which might explain why it works at 5V (Arduino), but not 3V3 (STM32).

A genuine DS18B20  is specified to work at 3.0V - but who knows about a fake?

Similarly, the timings may be off...

 

@Jevil again, likely that your STM32 implementation is marginal - so one just works, and the other just fails ...

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.
Andrew Neil
Super User
August 26, 2025

@Jevil wrote:

Two “DS18B20” sensors


Why the quotes? Are you suggesting that they may be fakes?

 


@Jevil wrote:
  • Stretched/relaxed timings around spec:

    • Reset low: ~520 µs, sample presence at ~70–80 µs after release

    • Write ‘1’: low 6–10 µs, slot ≥60 µs

    • Write ‘0’: low ~60 µs

    • Read: low 2–5 µs, sample at ~12–18 µs, slot ≥60 µs


How have you verified that you are actually achieving those timings?

On the 1-WireTM bus, timing is critical.

Having one sensor work, and the other not suggests that your timings are marginal...

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.
JevilAuthor
Associate
August 26, 2025


Why the quotes? Are you suggesting that they may be fakes?


Yes that is my assumption, but i'm not sure. The DS18B20 that does NOT work is from DFRobot.

 


How have you verified that you are actually achieving those timings?

On the 1-WireTM bus, timing is critical.

Having one sensor work, and the other not suggests that your timings are marginal...


I do not have a logic analyzer on-hand but will buy one. Is this one a good one?

I also know for a fact that if i decrease my clock speed to a lower number i.e. 16MHz instead of 32MHz that the DS18B20 that does work also won't work with the decreased clock speed (TIM Prescaler also lowered ofc).

So i'm also a bit afraid that my HSI is not very accurate thus also having a less accurate microsecond delay. \

I also tested it with the DHT22 and it works flawlessly on both clock speeds (but has less strict timings, if recall correctly)

Thanks!

Andrew Neil
Super User
August 26, 2025

@Jevil wrote:
I do not have a logic analyzer on-hand but will buy one. Is this one a good one?

That should be adequate.

Do you have an oscilloscope? That should be sufficient to see what's happening...

In fact, it's probably worth looking first on an oscilloscope - too see that there aren't any analogue issues...

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.