42#define CHIP_NAME "Sensirion SHT4X"
43#define MANUFACTURER_NAME "Sensirion"
44#define SUPPLY_VOLTAGE_MIN 1.08f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 100.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
54#define SHT4X_COMMAND_SOFT_RESET 0x94
55#define SHT4X_COMMAND_READ_SERIAL_NUMBER 0x89
69static uint8_t a_sht4x_write_read(
sht4x_handle_t *handle, uint8_t cmd, uint16_t delay, uint8_t *data, uint16_t len)
97static uint8_t a_sht4x_crc(uint8_t *data, uint16_t len)
99 const uint8_t POLYNOMIAL = 0x31;
104 for (j = len; j != 0; --j)
107 for (i = 8; i != 0; --i)
109 crc = (crc & 0x80) ? (crc << 1) ^ POLYNOMIAL : (crc<<1);
147 handle->
debug_print(
"sht4x: iic_deinit is null.\n");
153 handle->
debug_print(
"sht4x: iic_read_cmd is null.\n");
159 handle->
debug_print(
"sht4x: iic_write_cmd is null.\n");
180 handle->
debug_print(
"sht4x: write command failed.\n");
218 handle->
debug_print(
"sht4x: write command failed.\n");
224 handle->
debug_print(
"sht4x: iic deinit failed.\n");
294 uint16_t *temperature_raw,
float *temperature_s,
295 uint16_t *humidity_raw,
float *humidity_s)
313 res = a_sht4x_write_read(handle,
318 handle->
debug_print(
"sht4x: write command failed.\n");
327 res = a_sht4x_write_read(handle,
332 handle->
debug_print(
"sht4x: write command failed.\n");
341 res = a_sht4x_write_read(handle,
346 handle->
debug_print(
"sht4x: write command failed.\n");
355 res = a_sht4x_write_read(handle,
360 handle->
debug_print(
"sht4x: write command failed.\n");
369 res = a_sht4x_write_read(handle,
374 handle->
debug_print(
"sht4x: write command failed.\n");
383 res = a_sht4x_write_read(handle,
388 handle->
debug_print(
"sht4x: write command failed.\n");
397 res = a_sht4x_write_read(handle,
402 handle->
debug_print(
"sht4x: write command failed.\n");
411 res = a_sht4x_write_read(handle,
416 handle->
debug_print(
"sht4x: write command failed.\n");
425 res = a_sht4x_write_read(handle,
430 handle->
debug_print(
"sht4x: write command failed.\n");
439 memset(buf, 0,
sizeof(uint8_t) * 6);
444 if (a_sht4x_crc(buf + 0, 2) != buf[2])
450 if (a_sht4x_crc(buf + 3, 2) != buf[5])
456 *temperature_raw = (uint16_t)((((uint16_t)buf[0]) << 8) | buf[1]);
457 *humidity_raw = (uint16_t)((((uint16_t)buf[3]) << 8) | buf[4]);
458 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f;
459 *humidity_s = (((float)(*humidity_raw) / 65535.0f) * 125.0f - 6.0f);
460 if ((*humidity_s) > 100.0f)
462 *humidity_s = 100.0f;
464 if ((*humidity_s) < 0.0f)
502 handle->
debug_print(
"sht4x: write command failed.\n");
507 if (a_sht4x_crc(buf + 0, 2) != buf[2])
513 if (a_sht4x_crc(buf + 3, 2) != buf[5])
554 handle->
debug_print(
"sht4x: write command failed.\n");
585 return a_sht4x_write_read(handle, cmd, delay_ms, data, len);
#define SUPPLY_VOLTAGE_MAX
#define SHT4X_COMMAND_SOFT_RESET
chip command definition
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define SHT4X_COMMAND_READ_SERIAL_NUMBER
#define CHIP_NAME
chip information definition
uint8_t sht4x_read(sht4x_handle_t *handle, sht4x_mode_t mode, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read temperature and humidity
struct sht4x_handle_s sht4x_handle_t
sht4x handle structure definition
uint8_t sht4x_get_serial_number(sht4x_handle_t *handle, uint8_t num[4])
get serial number
sht4x_mode_t
sht4x mode enumeration definition
struct sht4x_info_s sht4x_info_t
sht4x information structure definition
sht4x_address_t
sht4x address enumeration definition
uint8_t sht4x_set_addr(sht4x_handle_t *handle, sht4x_address_t addr)
set the iic address
uint8_t sht4x_get_addr(sht4x_handle_t *handle, sht4x_address_t *addr)
get the iic address
uint8_t sht4x_init(sht4x_handle_t *handle)
initialize the chip
uint8_t sht4x_soft_reset(sht4x_handle_t *handle)
soft reset the chip
uint8_t sht4x_info(sht4x_info_t *info)
get chip's information
uint8_t sht4x_deinit(sht4x_handle_t *handle)
close the chip
@ SHT4X_MODE_HIGH_PRECISION_WITH_NO_HEATER
@ SHT4X_MODE_HIGH_PRECISION_WITH_HEATER_110MW_1S
@ SHT4X_MODE_MEDIUM_PRECISION_WITH_NO_HEATER
@ SHT4X_MODE_HIGH_PRECISION_WITH_HEATER_20MW_0P1S
@ SHT4X_MODE_HIGH_PRECISION_WITH_HEATER_200MW_1S
@ SHT4X_MODE_HIGH_PRECISION_WITH_HEATER_200MW_0P1S
@ SHT4X_MODE_LOWEST_PRECISION_WITH_NO_HEATER
@ SHT4X_MODE_HIGH_PRECISION_WITH_HEATER_110MW_0P1S
@ SHT4X_MODE_HIGH_PRECISION_WITH_HEATER_20MW_1S
uint8_t sht4x_write_read(sht4x_handle_t *handle, uint8_t cmd, uint16_t delay_ms, uint8_t *data, uint16_t len)
write and read bytes
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