42 #define CHIP_NAME "ASAIR AHT30"
43 #define MANUFACTURER_NAME "ASAIR"
44 #define SUPPLY_VOLTAGE_MIN 2.2f
45 #define SUPPLY_VOLTAGE_MAX 5.5f
46 #define MAX_CURRENT 0.60f
47 #define TEMPERATURE_MIN -40.0f
48 #define TEMPERATURE_MAX 85.0f
49 #define DRIVER_VERSION 1000
54 #define AHT30_ADDRESS 0x70
66 static uint8_t a_aht30_iic_read(
aht30_handle_t *handle, uint8_t *data, uint16_t len)
88 static uint8_t a_aht30_iic_write(
aht30_handle_t *handle, uint8_t *data, uint16_t len)
107 static uint8_t a_aht30_calc_crc(uint8_t *data, uint8_t len)
113 for (
byte = 0;
byte < len;
byte++)
116 for (i = 8; i > 0; --i)
118 if ((crc & 0x80) != 0)
120 crc = (crc << 1) ^ 0x31;
141 static uint8_t a_aht30_jh_reset_reg(
aht30_handle_t *handle, uint8_t addr)
149 if (a_aht30_iic_write(handle, buf, 3) != 0)
154 if (a_aht30_iic_read(handle, regs, 3) != 0)
159 buf[0] = 0xB0 | addr;
162 if (a_aht30_iic_write(handle, buf, 3) != 0)
202 handle->
debug_print(
"aht30: iic_deinit is null.\n");
208 handle->
debug_print(
"aht30: iic_read_cmd is null.\n");
214 handle->
debug_print(
"aht30: iic_write_cmd is null.\n");
232 if (a_aht30_iic_read(handle, &status, 1) != 0)
234 handle->
debug_print(
"aht30: read status failed.\n");
239 if ((status & 0x18) != 0x18)
241 if (a_aht30_jh_reset_reg(handle, 0x1B) != 0)
248 if (a_aht30_jh_reset_reg(handle, 0x1C) != 0)
255 if (a_aht30_jh_reset_reg(handle, 0x1E) != 0)
292 handle->
debug_print(
"aht30: iic deinit failed.\n");
318 uint32_t *humidity_raw, uint8_t *humidity_s)
334 if (a_aht30_iic_write(handle, buf, 3) != 0)
336 handle->
debug_print(
"aht30: sent command failed.\n");
341 if (a_aht30_iic_read(handle, buf, 7) != 0)
347 if ((buf[0] & 0x80) != 0)
349 handle->
debug_print(
"aht30: data is not ready.\n");
353 if (a_aht30_calc_crc(buf, 6) != buf[6])
360 *humidity_raw = (((uint32_t)buf[1]) << 16) |
361 (((uint32_t)buf[2]) << 8) |
362 (((uint32_t)buf[3]) << 0);
363 *humidity_raw = (*humidity_raw) >> 4;
364 *humidity_s = (uint8_t)((
float)(*humidity_raw)
365 / 1048576.0f * 100.0f);
366 *temperature_raw = (((uint32_t)buf[3]) << 16) |
367 (((uint32_t)buf[4]) << 8) |
368 (((uint32_t)buf[5]) << 0);
369 *temperature_raw = (*temperature_raw) & 0xFFFFF;
370 *temperature_s = (float)(*temperature_raw)
371 / 1048576.0f * 200.0f
407 if (a_aht30_iic_write(handle, buf, 3) != 0)
409 handle->
debug_print(
"aht30: sent command failed.\n");
414 if (a_aht30_iic_read(handle, buf, 7) != 0)
420 if ((buf[0] & 0x80) != 0)
422 handle->
debug_print(
"aht30: data is not ready.\n");
426 if (a_aht30_calc_crc(buf, 6) != buf[6])
433 *temperature_raw = (((uint32_t)buf[3]) << 16) |
434 (((uint32_t)buf[4]) << 8) |
435 (((uint32_t)buf[5]) << 0);
436 *temperature_raw = (*temperature_raw) & 0xFFFFF;
437 *temperature_s = (float)(*temperature_raw)
438 / 1048576.0f * 200.0f
474 if (a_aht30_iic_write(handle, buf, 3) != 0)
476 handle->
debug_print(
"aht30: sent command failed.\n");
481 if (a_aht30_iic_read(handle, buf, 7) != 0)
487 if ((buf[0] & 0x80) != 0)
489 handle->
debug_print(
"aht30: data is not ready.\n");
493 if (a_aht30_calc_crc(buf, 6) != buf[6])
500 *humidity_raw = (((uint32_t)buf[1]) << 16) |
501 (((uint32_t)buf[2]) << 8) |
502 (((uint32_t)buf[3]) << 0);
503 *humidity_raw = (*humidity_raw) >> 4;
504 *humidity_s = (uint8_t)((
float)(*humidity_raw)
505 / 1048576.0f * 100.0f);
532 if (a_aht30_iic_read(handle, status, 1) != 0)
565 if (a_aht30_iic_write(handle, buf, len) != 0)
598 if (a_aht30_iic_read(handle, buf, len) != 0)
#define SUPPLY_VOLTAGE_MAX
#define AHT30_ADDRESS
chip address definition
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
uint8_t aht30_deinit(aht30_handle_t *handle)
close the chip
uint8_t aht30_read_humidity(aht30_handle_t *handle, uint32_t *humidity_raw, uint8_t *humidity_s)
read the humidity data
uint8_t aht30_read_temperature(aht30_handle_t *handle, uint32_t *temperature_raw, float *temperature_s)
read the temperature
uint8_t aht30_init(aht30_handle_t *handle)
initialize the chip
uint8_t aht30_read_temperature_humidity(aht30_handle_t *handle, uint32_t *temperature_raw, float *temperature_s, uint32_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
uint8_t aht30_info(aht30_info_t *info)
get chip's information
uint8_t aht30_get_status(aht30_handle_t *handle, uint8_t *status)
get status
uint8_t aht30_get_reg(aht30_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
uint8_t aht30_set_reg(aht30_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
aht30 handle structure definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
aht30 information structure definition
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v