42#define CHIP_NAME "Sensirion SHTC3"
43#define MANUFACTURER_NAME "Sensirion"
44#define SUPPLY_VOLTAGE_MIN 1.62f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.9f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
54#define SHTC3_ADDRESS (0x70 << 1)
59#define SHTC3_COMMAND_READ_ID 0xEFC8U
60#define SHTC3_COMMAND_SOFT_RESET 0x805DU
61#define SHTC3_COMMAND_SLEEP 0xB098U
62#define SHTC3_COMMAND_WAKEUP 0x3517U
63#define SHTC3_COMMAND_MEAS_T_POLLING 0x7866U
64#define SHTC3_COMMAND_MEAS_T_CLOCKSTR 0x7CA2U
65#define SHTC3_COMMAND_MEAS_RH_POLLING 0x58E0U
66#define SHTC3_COMMAND_MEAS_RH_CLOCKSTR 0x5C24U
67#define SHTC3_COMMAND_LP_MEAS_T_POLLING 0x609CU
68#define SHTC3_COMMAND_LP_MEAS_T_CLOCKSTR 0x6458U
69#define SHTC3_COMMAND_LP_MEAS_RH_POLLING 0x401AU
70#define SHTC3_COMMAND_LP_MEAS_RH_CLOCKSTR 0x44DEU
102static uint8_t a_shtc3_read(
shtc3_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len)
119static uint8_t a_shtc3_crc(uint8_t *data, uint16_t len)
121 const uint8_t POLYNOMIAL = 0x31;
125 for (j = len; j != 0; --j)
128 for (i = 8; i != 0; --i)
130 crc = (crc & 0x80) ? (crc << 1) ^ POLYNOMIAL : (crc<<1);
171 handle->
debug_print(
"shtc3: iic_deinit is null.\n");
177 handle->
debug_print(
"shtc3: iic_read_address16 is null.\n");
183 handle->
debug_print(
"shtc3: iic_write_address16 is null.\n");
202 res = a_shtc3_write(handle, command);
205 handle->
debug_print(
"shtc3: write command failed.\n");
213 res = a_shtc3_read(handle, command, (uint8_t *)data, 3);
221 if (a_shtc3_crc((uint8_t *)data, 2) != data[2])
228 if (((data[0] & 0x08) != 0x08) || ((data[1] & 0x3F) != 0x7))
266 res = a_shtc3_write(handle, command);
269 handle->
debug_print(
"shtc3: write command failed.\n");
277 handle->
debug_print(
"shtc3: iic deinit failed.\n");
302 uint16_t *temperature_raw,
float *temperature_s,
303 uint16_t *humidity_raw,
float *humidity_s)
326 res = a_shtc3_read(handle, command, (uint8_t *)data, 3);
333 if (a_shtc3_crc((uint8_t *)data, 2) != data[2])
339 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
340 *temperature_s = (float)(*temperature_raw) / 65536.0f * 175.0f - 45.0f;
350 res = a_shtc3_read(handle, command, (uint8_t *)data, 3);
357 if (a_shtc3_crc((uint8_t *)data, 2) != data[2])
363 *humidity_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
364 *humidity_s = (float)(*humidity_raw) / 65536.0f * 100.0f;
385 uint16_t *temperature_raw,
float *temperature_s,
386 uint16_t *humidity_raw,
float *humidity_s)
409 res = a_shtc3_read(handle, command, (uint8_t *)data, 3);
416 if (a_shtc3_crc((uint8_t *)data, 2) != data[2])
422 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
423 *temperature_s = (float)(*temperature_raw) / 65536.0f * 175.0f - 45.0f;
433 res = a_shtc3_read(handle, command, (uint8_t *)data, 3);
440 if (a_shtc3_crc((uint8_t *)data, 2) != data[2])
446 *humidity_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
447 *humidity_s = (float)(*humidity_raw) / 65536.0f * 100.0f;
477 res = a_shtc3_write(handle, command);
480 handle->
debug_print(
"shtc3: write command failed.\n");
514 res = a_shtc3_write(handle, command);
517 handle->
debug_print(
"shtc3: write command failed.\n");
550 res = a_shtc3_write(handle, command);
553 handle->
debug_print(
"shtc3: write command failed.\n");
584 return a_shtc3_write(handle, command);
611 return a_shtc3_read(handle, command, buf, len);
#define SHTC3_COMMAND_SOFT_RESET
#define SHTC3_COMMAND_LP_MEAS_RH_POLLING
#define SHTC3_COMMAND_MEAS_T_POLLING
#define SHTC3_COMMAND_LP_MEAS_T_CLOCKSTR
#define SHTC3_COMMAND_READ_ID
chip command definition
#define SHTC3_COMMAND_MEAS_RH_CLOCKSTR
#define SHTC3_COMMAND_MEAS_RH_POLLING
#define SUPPLY_VOLTAGE_MAX
#define SHTC3_ADDRESS
chip address definition
#define SHTC3_COMMAND_MEAS_T_CLOCKSTR
#define SHTC3_COMMAND_SLEEP
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define SHTC3_COMMAND_WAKEUP
#define SHTC3_COMMAND_LP_MEAS_RH_CLOCKSTR
#define CHIP_NAME
chip information definition
#define SHTC3_COMMAND_LP_MEAS_T_POLLING
shtc3_bool_t
shtc3 bool enumeration definition
uint8_t shtc3_init(shtc3_handle_t *handle)
initialize the chip
uint8_t shtc3_wakeup(shtc3_handle_t *handle)
wakeup
uint8_t shtc3_info(shtc3_info_t *info)
get chip's information
uint8_t shtc3_read(shtc3_handle_t *handle, shtc3_bool_t clock_stretching_enable, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
normal read
uint8_t shtc3_deinit(shtc3_handle_t *handle)
close the chip
uint8_t shtc3_soft_reset(shtc3_handle_t *handle)
soft reset the chip
struct shtc3_handle_s shtc3_handle_t
shtc3 handle structure definition
uint8_t shtc3_sleep(shtc3_handle_t *handle)
sleep
uint8_t shtc3_read_low_power(shtc3_handle_t *handle, shtc3_bool_t clock_stretching_enable, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read in low power mode
struct shtc3_info_s shtc3_info_t
shtc3 information structure definition
uint8_t shtc3_set_reg(shtc3_handle_t *handle, uint16_t command)
set the chip register
uint8_t shtc3_get_reg(shtc3_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
get the chip register
void(* delay_ms)(uint32_t ms)
uint8_t(* iic_read_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v