43 #define CHIP_NAME "ASAIR DHT11"
44 #define MANUFACTURER_NAME "ASAIR"
45 #define SUPPLY_VOLTAGE_MIN 3.3f
46 #define SUPPLY_VOLTAGE_MAX 5.5f
47 #define MAX_CURRENT 1.0f
48 #define TEMPERATURE_MIN -20.0f
49 #define TEMPERATURE_MAX 60.0f
50 #define DRIVER_VERSION 2000
69 handle->
debug_print(
"dht11: bus write 0 failed.\n");
79 handle->
debug_print(
"dht11: bus write 1 failed.\n");
84 res = handle->
bus_read((uint8_t *)&value);
92 while ((value != 0) && (retry < 100))
94 res = handle->
bus_read((uint8_t *)&value);
116 res = handle->
bus_read((uint8_t *)&value);
124 while ((!value) && (retry < 100))
126 res = handle->
bus_read((uint8_t *)&value);
158 static uint8_t a_dht11_read_bit(
dht11_handle_t *handle, uint8_t *value)
163 res = handle->
bus_read((uint8_t *)value);
170 while (((*value) != 0) && (retry < 100))
172 res = handle->
bus_read((uint8_t *)value);
183 res = handle->
bus_read((uint8_t *)value);
190 while ((!(*value)) && (retry < 100))
192 res = handle->
bus_read((uint8_t *)value);
203 res = handle->
bus_read((uint8_t *)value);
225 static uint8_t a_dht11_read_byte(
dht11_handle_t *handle, uint8_t *
byte)
232 for (i = 0; i < 8; i++)
235 res = a_dht11_read_bit(handle, (uint8_t *)&value);
274 if (a_dht11_reset(handle) == 0)
277 for (i = 0; i < 5; i++)
279 if (a_dht11_read_byte(handle, (uint8_t *)&buf[i]) != 0)
288 if ((buf[0] + buf[1] + buf[2] + buf[3]) == buf[4])
290 *raw = (uint16_t)buf[0] << 8 | buf[1];
297 handle->
debug_print(
"dht11: data check failed.\n");
325 uint16_t *humidity_raw, uint8_t *humidity_s)
339 if (a_dht11_reset(handle) == 0)
342 for (i = 0; i < 5; i++)
344 if (a_dht11_read_byte(handle, (uint8_t *)&buf[i]) != 0)
353 if ((buf[0] + buf[1] + buf[2] + buf[3]) == buf[4])
357 *temperature_raw = (uint16_t)buf[2] << 8 | buf[3];
358 *temperature_s= (float)(-(buf[2] * 10 +
359 (buf[3] & ~(1<<7)))) / 10.0f;
363 *temperature_raw = (uint16_t)buf[2] << 8 | buf[3];
364 *temperature_s= (float)(buf[2]*10 + buf[3]) / 10.0f;
366 *humidity_raw = (uint16_t)buf[0] << 8 | buf[1];
367 *humidity_s = buf[0];
373 handle->
debug_print(
"dht11: data check failed.\n");
412 if (a_dht11_reset(handle) == 0)
415 for (i = 0; i < 5; i++)
417 if (a_dht11_read_byte(handle, (uint8_t *)&buf[i]) != 0)
426 if ((buf[0] + buf[1] + buf[2] + buf[3]) == buf[4])
430 *raw = (uint16_t)buf[2] << 8 | buf[3];
431 *s= (float)(-(buf[2] * 10 + (buf[3] & ~(1<<7)))) / 10.0f;
435 *raw = (uint16_t)buf[2] << 8 | buf[3];
436 *s= (float)(buf[2] * 10 + buf[3]) / 10.0f;
443 handle->
debug_print(
"dht11: data check failed.\n");
485 handle->
debug_print(
"dht11: bus_deinit is null.\n");
497 handle->
debug_print(
"dht11: bus_write is null.\n");
515 handle->
debug_print(
"dht11: enable_irq is null.\n");
521 handle->
debug_print(
"dht11: disable_irq is null.\n");
532 if (a_dht11_reset(handle) != 0)
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
uint8_t dht11_read_temperature_humidity(dht11_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
uint8_t dht11_info(dht11_info_t *info)
get chip's information
uint8_t dht11_init(dht11_handle_t *handle)
initialize the chip
uint8_t dht11_read_humidity(dht11_handle_t *handle, uint16_t *raw, uint8_t *s)
read the humidity data
uint8_t dht11_deinit(dht11_handle_t *handle)
close the chip
uint8_t dht11_read_temperature(dht11_handle_t *handle, uint16_t *raw, float *s)
read the temperature data
dht11 handle structure definition
uint8_t(* bus_deinit)(void)
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
void(* delay_us)(uint32_t us)
void(* disable_irq)(void)
uint8_t(* bus_read)(uint8_t *value)
uint8_t(* bus_write)(uint8_t value)
uint8_t(* bus_init)(void)
dht11 info structure definition
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v