I got a DHT11 temperature and humidity sensor in my hands. Measures humidity in the range of 20-90% and temperature from 0 to 50 ° C. Error of measurement of humidity of 5%, temperatures of 2 ° C. Capture time 1 sec. Single wire (
datashit ) communication interface. Such modest parameters limit the scope of the sensor only for household conditions.

I wanted to compare the
device readings
on the HCH1000 + DS18B20 with the DHT11.
I mistakenly concluded that the DHT11 and DS18B20 get along on the same bus. It turned out they have completely different protocols. After an unsuccessful experience, hastily assembled a device to establish the truth.

I did not find the finished DHT11 library for STM32. For Arduino
here . The single wire communication protocol has nothing to do with 1-wire. The difference between 0 and 1 is obtained from the difference in pulse duration.

First, we keep about 20 ms low bus level, then let it go, after 20 ms the sensor clamps it to 0 itself and holds 80 µs and then releases it for 80 µs (generates a presence signal), followed by 40 data bits, with the same start - by pinching the tire on 50 μs and a bit. bit 0 is about 28 μs, bit 1 is 70 μs. Well, at parting, the sensor clamps and releases the tire. 40 data bits is 5 bytes, of which the first two are humidity, the next 2 is temperature and parity is byte. The parity byte is equal to the sum of the previous bytes. The 1st byte and 3rd byte transfer the values, 2 and 4 I understand are reserved for the tenths.
The easiest way to read the duration of the pulses and write them into an array. Then transform this array into an array of bytes. This is how the dht11.c library was born.
uint16_t read_cycle(uint16_t cur_tics, uint8_t neg_tic){ uint16_t cnt_tics; if (cur_tics < MAX_TICS) cnt_tics = 0; if (neg_tic) { while (!GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_3)&&(cnt_tics<MAX_TICS)){ cnt_tics++; } } else { while (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_3)&&(cnt_tics<MAX_TICS)){ cnt_tics++; } } return cnt_tics; } uint8_t read_DHT11(uint8_t *buf){ uint16_t dt[42]; uint16_t cnt; uint8_t i, check_sum;
The project containing the dht11.c library is
here .