2025-08-26 3:53 AM
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)
2025-08-26 4:03 AM
Hi Jevil,
DS18B20 are known to be faked frequently.
Before wasting much time I would buy some from a reliable source.
BR Klaus
2025-08-26 4:09 AM
@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...
2025-08-26 4:16 AM
@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 ...
2025-08-26 4:49 AM
Hey thanks for the reply,
The sensor that does not work with my software is from DFRobot. I though these were reliable since other vendors (i.e. Digikey are selling those aswell)
I have no clue where the sensor comes from that does work since I haven't bough that one myself.
2025-08-26 4:58 AM
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!