452
uint8_t read_byte(void) { uint8_t num = 0; for (i = 0; i < 8; i++) { while (!HAL_GPIO_ReadPin(DHT22_GPIO_Port, DHT22_Pin)) {}; __HAL_TIM_SET_COUNTER(&htim1, 0); while (HAL_GPIO_ReadPin(DHT22_GPIO_Port, DHT22_Pin)) {}; if (__HAL_TIM_GET_COUNTER(&htim1) > 40) // 40μs threshold num |= (1 << (7 - i)); } return num; }