Temperature and humidity module: single-bus digital signal output

Hardware wiring

1

DHT11 temperature and humidity moduleSTM32F103RCT6
VCC5V/3.3V
OUTPA1
NC 
GNDGND

Brief principle

Communication and synchronization between STM32F103RCT6 and DHT11 in a single-bus data format.

A full data transfer is 40bit, high first-out.

Data format:

8bit humidity integer data 8bit humidity decimal data 8bi temperature integer data 8bit temperature decimal data 8bit checksum

When the data is transmitted correctly,

Checksum = 8-bit humidity integer data + 8-bit humidity decimal data + 8bi temperature integer data + 8-bit temperature decimal data

After the user MCU sends a start signal, DHT11 switches from low-power mode to high-speed mode, waits for the host start signal to end, DHT11 sends a response signal, sends 40bit data, and triggers a signal acquisition, and the user can choose to read part of the data.

In slave mode, DHT11 receives a start signal to trigger a temperature and humidity acquisition, if it does not receive the host to send a start signal, DHT11 will not actively collect temperature and humidity, and after collecting data, switch to low-speed mode.

Main code

main.c

SysTick.c

SysTick.h

UART.c

UART.h

DHT11.c

DHT11.h

Phenomenon

After downloading the program, press the Reset key once, and the downloaded program will run.

At this time, the serial port will continuously print the temperature and humidity information measured by the temperature and humidity sensor.

2