Course project · driver and debugging
Shanghai University · Embedded Systems Design (autumn 2021)
No sensor library — the 40-bit DHT11 frame is read with GPIO and Timer_A: 18 ms start pulse, 40 µs sampling point, 8-bit checksum. The code is split into a reusable driver and a UART demo, with the original single-file version kept for reference.
The DHT11 has no SPI or I²C interface: one data line carries 40 bits as pulse widths. The course required an MSP432P401R + DriverLib implementation without a sensor library, which makes it a compact exercise in GPIO, timers, interrupts and UART.

The supply range is 3.0–5.5 V, so 3.3 V matches the MCU logic. The data line is open-drain; without a pull-up it floats or stays high, which is the usual reason a read fails.
A transaction has three parts:

The 40 µs sample point is the heart of the driver: earlier and both bits are high; later and even a 1 may have ended.
dht11.c: start signal, response detection, read_byte() bit decoding, checksum;dht11.h: dht11_init(), dht11_read(), dht11_delay_ms();main.c: 24 MHz DCO, UART A0 at 115200, one reading every 2 s printed as TxxC RHxx%.delay_us(n) uses Timer_A: CCR0 is set to 24×n, the timer is started, and the interrupt only sets a flag. No busy-wait calibration, and changing the clock means changing one constant.
read_byte() waits for the 50 µs low to end, delays 40 µs, samples the line, then waits for the high to end. A guard counter prevents an infinite wait if the sensor disappears.
The course code was a single file. It worked, but:
time_count was not volatile, so the compiler could cache it and the wait loop could never finish;flag was uninitialised, so a checksum failure returned a random value;delay_us and delay_ms reconfigured Timer_A repeatedly, and delay_ms called delay_us once per millisecond;The split version fixes these: volatile, initialisation to 0, -1 on failure, and an error message in main. The original file is kept in legacy/.
On an MSP432P401R LaunchPad with a DHT11, the UART prints stable readings and the LED toggles on every successful read. The limits are real:
A next step would be input capture + DMA so the CPU can do other work during the 40-bit frame, but that is beyond the course brief.
Code and wiring notes are in the repository; the implementation story is in this post.