42#define CHIP_NAME "ASAIR AHT40"
43#define MANUFACTURER_NAME "ASAIR"
44#define SUPPLY_VOLTAGE_MIN 2.0f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.46f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 120.0f
49#define DRIVER_VERSION 1000
54#define AHT40_ADDRESS 0x88U
66static uint8_t a_aht40_iic_read(
aht40_handle_t *handle, uint8_t *data, uint16_t len)
86static uint8_t a_aht40_iic_write(
aht40_handle_t *handle, uint8_t *data, uint16_t len)
103static uint8_t a_aht40_calc_crc(uint8_t *data, uint8_t len)
109 for (
byte = 0;
byte < len;
byte++)
112 for (i = 8; i > 0; --i)
114 if ((crc & 0x80) != 0)
116 crc = (crc << 1) ^ 0x31;
158 handle->
debug_print(
"aht40: iic_deinit is null.\n");
164 handle->
debug_print(
"aht40: iic_read_cmd is null.\n");
170 handle->
debug_print(
"aht40: iic_write_cmd is null.\n");
216 handle->
debug_print(
"aht40: iic deinit failed.\n");
241 uint16_t *humidity_raw,
float *humidity_s)
255 if (a_aht40_iic_write(handle, buf, 1) != 0)
257 handle->
debug_print(
"aht40: sent command failed.\n");
262 if (a_aht40_iic_read(handle, buf, 6) != 0)
268 if (a_aht40_calc_crc(buf + 0, 2) != buf[2])
274 if (a_aht40_calc_crc(buf + 3, 2) != buf[5])
281 *humidity_raw = (((uint16_t)buf[3]) << 8) |
282 (((uint16_t)buf[4]) << 0);
283 *humidity_s = (float)(*humidity_raw) / 65535.0f *
285 *temperature_raw = (((uint16_t)buf[0]) << 8) |
286 (((uint16_t)buf[1]) << 0);
287 *temperature_s = (float)(*temperature_raw) / 65535.0f *
320 if (a_aht40_iic_write(handle, buf, 1) != 0)
322 handle->
debug_print(
"aht40: sent command failed.\n");
327 if (a_aht40_iic_read(handle, buf, 6) != 0)
333 if (a_aht40_calc_crc(buf + 0, 2) != buf[2])
339 if (a_aht40_calc_crc(buf + 3, 2) != buf[5])
346 *temperature_raw = (((uint16_t)buf[0]) << 8) |
347 (((uint16_t)buf[1]) << 0);
348 *temperature_s = (float)(*temperature_raw) / 65535.0f *
381 if (a_aht40_iic_write(handle, buf, 1) != 0)
383 handle->
debug_print(
"aht40: sent command failed.\n");
388 if (a_aht40_iic_read(handle, buf, 6) != 0)
394 if (a_aht40_calc_crc(buf + 0, 2) != buf[2])
400 if (a_aht40_calc_crc(buf + 3, 2) != buf[5])
407 *humidity_raw = (((uint16_t)buf[3]) << 8) |
408 (((uint16_t)buf[4]) << 0);
409 *humidity_s = (float)(*humidity_raw) / 65535.0f *
438 if (a_aht40_iic_write(handle, buf, len) != 0)
469 if (a_aht40_iic_read(handle, buf, len) != 0)
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define AHT40_ADDRESS
chip address definition
#define CHIP_NAME
chip information definition
struct aht40_info_s aht40_info_t
aht40 information structure definition
uint8_t aht40_init(aht40_handle_t *handle)
initialize the chip
uint8_t aht40_read_humidity(aht40_handle_t *handle, uint16_t *humidity_raw, float *humidity_s)
read the humidity data
uint8_t aht40_info(aht40_info_t *info)
get chip's information
struct aht40_handle_s aht40_handle_t
aht40 handle structure definition
uint8_t aht40_read_temperature(aht40_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read the temperature
uint8_t aht40_read_temperature_humidity(aht40_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read the temperature and humidity data
uint8_t aht40_deinit(aht40_handle_t *handle)
close the chip
uint8_t aht40_get_reg(aht40_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
uint8_t aht40_set_reg(aht40_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
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)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v