42#define CHIP_NAME "ASAIR AHT25"
43#define MANUFACTURER_NAME "ASAIR"
44#define SUPPLY_VOLTAGE_MIN 2.2f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.98f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 80.0f
49#define DRIVER_VERSION 1000
54#define AHT25_ADDRESS 0x70
66static uint8_t a_aht25_iic_read(
aht25_handle_t *handle, uint8_t *data, uint16_t len)
86static uint8_t a_aht25_iic_write(
aht25_handle_t *handle, uint8_t *data, uint16_t len)
103static uint8_t a_aht25_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;
137static uint8_t a_aht25_jh_reset_reg(
aht25_handle_t *handle, uint8_t addr)
145 if (a_aht25_iic_write(handle, buf, 3) != 0)
150 if (a_aht25_iic_read(handle, regs, 3) != 0)
155 buf[0] = 0xB0 | addr;
158 if (a_aht25_iic_write(handle, buf, 3) != 0)
198 handle->
debug_print(
"aht25: iic_deinit is null.\n");
204 handle->
debug_print(
"aht25: iic_read_cmd is null.\n");
210 handle->
debug_print(
"aht25: iic_write_cmd is null.\n");
228 if (a_aht25_iic_read(handle, &status, 1) != 0)
230 handle->
debug_print(
"aht25: read status failed.\n");
235 if ((status & 0x18) != 0x18)
237 if (a_aht25_jh_reset_reg(handle, 0x1B) != 0)
244 if (a_aht25_jh_reset_reg(handle, 0x1C) != 0)
251 if (a_aht25_jh_reset_reg(handle, 0x1E) != 0)
288 handle->
debug_print(
"aht25: iic deinit failed.\n");
314 uint32_t *humidity_raw, uint8_t *humidity_s)
331 if (a_aht25_iic_write(handle, buf, 3) != 0)
333 handle->
debug_print(
"aht25: sent command failed.\n");
338 if (a_aht25_iic_read(handle, &status, 1) != 0)
340 handle->
debug_print(
"aht25: read status failed.\n");
344 if ((status & 0x80) == 0)
346 if (a_aht25_iic_read(handle, buf, 7) != 0)
352 if (a_aht25_calc_crc(buf, 6) != buf[6])
359 *humidity_raw = (((uint32_t)buf[1]) << 16) |
360 (((uint32_t)buf[2]) << 8) |
361 (((uint32_t)buf[3]) << 0);
362 *humidity_raw = (*humidity_raw) >> 4;
363 *humidity_s = (uint8_t)((
float)(*humidity_raw)
364 / 1048576.0f * 100.0f);
365 *temperature_raw = (((uint32_t)buf[3]) << 16) |
366 (((uint32_t)buf[4]) << 8) |
367 (((uint32_t)buf[5]) << 0);
368 *temperature_raw = (*temperature_raw) & 0xFFFFF;
369 *temperature_s = (float)(*temperature_raw)
370 / 1048576.0f * 200.0f
377 handle->
debug_print(
"aht25: data is not ready.\n");
414 if (a_aht25_iic_write(handle, buf, 3) != 0)
416 handle->
debug_print(
"aht25: sent command failed.\n");
421 if (a_aht25_iic_read(handle, &status, 1) != 0)
423 handle->
debug_print(
"aht25: read status failed.\n");
427 if ((status & 0x80) == 0)
429 if (a_aht25_iic_read(handle, buf, 7) != 0)
435 if (a_aht25_calc_crc(buf, 6) != buf[6])
442 *temperature_raw = (((uint32_t)buf[3]) << 16) |
443 (((uint32_t)buf[4]) << 8) |
444 (((uint32_t)buf[5]) << 0);
445 *temperature_raw = (*temperature_raw) & 0xFFFFF;
446 *temperature_s = (float)(*temperature_raw)
447 / 1048576.0f * 200.0f
454 handle->
debug_print(
"aht25: data is not ready.\n");
491 if (a_aht25_iic_write(handle, buf, 3) != 0)
493 handle->
debug_print(
"aht25: sent command failed.\n");
498 if (a_aht25_iic_read(handle, &status, 1) != 0)
500 handle->
debug_print(
"aht25: read status failed.\n");
504 if ((status & 0x80) == 0)
506 if (a_aht25_iic_read(handle, buf, 7) != 0)
512 if (a_aht25_calc_crc(buf, 6) != buf[6])
519 *humidity_raw = (((uint32_t)buf[1]) << 16) |
520 (((uint32_t)buf[2]) << 8) |
521 (((uint32_t)buf[3]) << 0);
522 *humidity_raw = (*humidity_raw) >> 4;
523 *humidity_s = (uint8_t)((
float)(*humidity_raw)
524 / 1048576.0f * 100.0f);
530 handle->
debug_print(
"aht25: data is not ready.\n");
559 if (a_aht25_iic_write(handle, buf, len) != 0)
590 if (a_aht25_iic_read(handle, buf, len) != 0)
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
#define AHT25_ADDRESS
chip address definition
uint8_t aht25_info(aht25_info_t *info)
get chip's information
struct aht25_info_s aht25_info_t
aht25 information structure definition
uint8_t aht25_init(aht25_handle_t *handle)
initialize the chip
uint8_t aht25_read_temperature_humidity(aht25_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 aht25_deinit(aht25_handle_t *handle)
close the chip
uint8_t aht25_read_humidity(aht25_handle_t *handle, uint32_t *humidity_raw, uint8_t *humidity_s)
read the humidity data
struct aht25_handle_s aht25_handle_t
aht25 handle structure definition
uint8_t aht25_read_temperature(aht25_handle_t *handle, uint32_t *temperature_raw, float *temperature_s)
read the temperature
uint8_t aht25_get_reg(aht25_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
uint8_t aht25_set_reg(aht25_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