Here's how you can wire a DS18B20 digital temperature sensor to an STM32 microcontroller, such as the STM32F103 or STM32F407, and a brief on how to read its data using HAL or bare-metal code.
1. DS18B20 Pinout
If you're using the parasite power mode, DQ and VDD are connected together (not recommended for simplicity).
2. Wiring DS18B20 to STM32 (Normal Mode)
Components:
- DS18B20
- 4.7 kΩ resistor (pull-up)
- STM32 board (e.g., STM32F103C8T6 Blue Pill)
- Breadboard and jumper wires
Connections:
Wiring Diagram (Textual):
scss
STM32 3.3V ────┬───────── VDD (DS18B20)
│
[4.7kΩ]
│
GPIO PA1 ─────┴───────── DQ (DS18B20)
GND ──────────────────── GND (DS18B20)
3. STM32 Software Notes (Using HAL)
Option A: Use a 1-Wire Library (e.g., for HAL)
You’ll need:
- A 1-Wire library (bit-banged or timer-based)
- A DS18B20 driver built on 1-Wire
Popular 1-Wire/DS18B20 libraries:
- DS18B20_HAL (C-based, portable)
- Middlewares from STM32CubeIDE GitHub projects
Option B: Bit-Banging Your Own (Advanced)
Write 1-Wire protocol manually using GPIO:
- Reset pulse → pull low for ≥480 µs
- Wait for presence → check if sensor pulls low
- Send/read bits using timed pulses
4. Example Libraries
STM32 HAL DS18B20 GitHub Libraries:
- https://github.com/ControllingTheInter.net/STM32_DS18B20
- https://github.com/MaJerle/OneWire (OneWire + DS18B20 support)
Summary
Top comments (0)