43#define CHIP_NAME "Sensirion SHT30"
44#define MANUFACTURER_NAME "Sensirion"
45#define SUPPLY_VOLTAGE_MIN 2.4f
46#define SUPPLY_VOLTAGE_MAX 5.5f
47#define MAX_CURRENT 1.5f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 125.0f
50#define DRIVER_VERSION 2000
55#define SHT30_COMMAND_FETCH_DATA 0xE000U
56#define SHT30_COMMAND_ART 0x2B32U
57#define SHT30_COMMAND_BREAK 0x3093U
58#define SHT30_COMMAND_SOFT_RESET 0x30A2U
59#define SHT30_COMMAND_HEATER_ENABLE 0x306DU
60#define SHT30_COMMAND_HEATER_DISABLE 0x3066U
61#define SHT30_COMMAND_READ_STATUS 0xF32DU
62#define SHT30_COMMAND_CLEAR_STATUS 0x3041U
63#define SHT30_COMMAND_GET_SERIAL_NUMBER 0x3682U
64#define SHT30_COMMAND_READ_HIGH_ALERT_LIMIT_SET 0xE11FU
65#define SHT30_COMMAND_READ_HIGH_ALERT_LIMIT_CLEAR 0xE114U
66#define SHT30_COMMAND_READ_LOW_ALERT_LIMIT_SET 0xE102U
67#define SHT30_COMMAND_READ_LOW_ALERT_LIMIT_CLEAR 0xE109U
68#define SHT30_COMMAND_WRITE_HIGH_ALERT_LIMIT_SET 0x611DU
69#define SHT30_COMMAND_WRITE_HIGH_ALERT_LIMIT_CLEAR 0x6116U
70#define SHT30_COMMAND_WRITE_LOW_ALERT_LIMIT_SET 0x6100U
71#define SHT30_COMMAND_WRITE_LOW_ALERT_LIMIT_CLEAR 0x610BU
105static uint8_t a_sht30_write_bytes(
sht30_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len)
128static uint8_t a_sht30_read(
sht30_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len)
147static uint8_t a_sht30_crc(uint8_t *data, uint16_t len)
149 const uint8_t POLYNOMIAL = 0x31;
153 for (j = len; j != 0; --j)
156 for (i = 8; i != 0; --i)
158 crc = (crc & 0x80) ? (crc << 1) ^ POLYNOMIAL : (crc<<1);
196 handle->
debug_print(
"sht30: iic_deinit is null.\n");
202 handle->
debug_print(
"sht30: iic_read_address16 is null.\n");
208 handle->
debug_print(
"sht30: iic_write_address16 is null.\n");
226 res = a_sht30_write(handle, command);
229 handle->
debug_print(
"sht30: write command failed.\n");
265 res = a_sht30_write(handle, command);
268 handle->
debug_print(
"sht30: write command failed.\n");
274 handle->
debug_print(
"sht30: iic deinit failed.\n");
300 handle->
iic_addr = (uint8_t)addr_pin;
353 memset(data, 0,
sizeof(uint8_t) * 3);
355 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
358 handle->
debug_print(
"sht30: read status failed.\n");
362 if (a_sht30_crc((uint8_t *)data, 2) == data[2])
364 *status = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
401 res = a_sht30_write(handle, command);
404 handle->
debug_print(
"sht30: write command failed.\n");
480 uint16_t *temperature_raw,
float *temperature_s,
481 uint16_t *humidity_raw,
float *humidity_s
509 handle->
debug_print(
"sht30: clock stretching is invalid.\n");
526 handle->
debug_print(
"sht30: clock stretching is invalid.\n");
543 handle->
debug_print(
"sht30: clock stretching is invalid.\n");
550 handle->
debug_print(
"sht30: repeatability is invalid.\n");
554 memset(data, 0,
sizeof(uint8_t) * 6);
555 res = a_sht30_read(handle, command, (uint8_t *)data, 6);
562 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
568 if (a_sht30_crc((uint8_t *)&data[3], 2) != data[5])
574 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
575 *humidity_raw = (uint16_t)((((uint16_t)data[3]) << 8) | data[4]);
576 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f;
577 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f;
696 handle->
debug_print(
"sht30: repeatability is invalid.\n");
700 res = a_sht30_write(handle, command);
703 handle->
debug_print(
"sht30: write command failed.\n");
736 res = a_sht30_write(handle, command);
739 handle->
debug_print(
"sht30: write command failed.\n");
762 uint16_t *temperature_raw,
float *temperature_s,
763 uint16_t *humidity_raw,
float *humidity_s)
779 res = a_sht30_read(handle, command, (uint8_t *)data, 6);
786 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
792 if (a_sht30_crc((uint8_t *)&data[3], 2) != data[5])
798 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
799 *humidity_raw = (uint16_t)((((uint16_t)data[3]) << 8) | data[4]);
800 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f;
801 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f;
831 res = a_sht30_write(handle, command);
834 handle->
debug_print(
"sht30: write command failed.\n");
867 res = a_sht30_write(handle, command);
870 handle->
debug_print(
"sht30: write command failed.\n");
918 res = a_sht30_write(handle, command);
921 handle->
debug_print(
"sht30: write command failed.\n");
956 res = a_sht30_read(handle, command, (uint8_t *)data, 6);
963 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
969 if (a_sht30_crc((uint8_t *)&data[3], 2) != data[5])
1011 data[0] = (set >> 8) & 0xFF;
1012 data[1] = (set >> 0) & 0xFF;
1013 data[2] = a_sht30_crc((uint8_t *)data, 2);
1014 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1023 data[0] = (clear >> 8) & 0xFF;
1024 data[1] = (clear >> 0) & 0xFF;
1025 data[2] = a_sht30_crc((uint8_t *)data, 2);
1026 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1065 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1068 handle->
debug_print(
"sht30: read data failed.\n");
1072 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1074 handle->
debug_print(
"sht30: crc check failed.\n");
1078 *set = ((uint16_t)data[0] << 8) | data[1];
1081 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1084 handle->
debug_print(
"sht30: read data failed.\n");
1088 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1090 handle->
debug_print(
"sht30: crc check failed.\n");
1094 *clear = ((uint16_t)data[0] << 8) | data[1];
1127 data[0] = (set >> 8) & 0xFF;
1128 data[1] = (set >> 0) & 0xFF;
1129 data[2] = a_sht30_crc((uint8_t *)data, 2);
1130 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1139 data[0] = (clear >> 8) & 0xFF;
1140 data[1] = (clear >> 0) & 0xFF;
1141 data[2] = a_sht30_crc((uint8_t *)data, 2);
1142 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1181 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1184 handle->
debug_print(
"sht30: read data failed.\n");
1188 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1190 handle->
debug_print(
"sht30: crc check failed.\n");
1194 *set = ((uint16_t)data[0] << 8) | data[1];
1197 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1200 handle->
debug_print(
"sht30: read data failed.\n");
1204 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1206 handle->
debug_print(
"sht30: crc check failed.\n");
1210 *clear = ((uint16_t)data[0] << 8) | data[1];
1241 r_t = (uint16_t)(((temperature + 45.0f) / 175.0f) * 65535.0f);
1243 r_h = (uint16_t)((humidity / 100.0f) * 65535.0f);
1245 *reg = (r_h << 9) | r_t;
1276 memset(data, 0,
sizeof(uint8_t) * 3);
1278 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1281 handle->
debug_print(
"sht30: read status failed.\n");
1285 if (a_sht30_crc((uint8_t *)data, 2) == data[2])
1287 status = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
1289 res = a_sht30_write(handle, command);
1292 handle->
debug_print(
"sht30: write command failed.\n");
1323 handle->
debug_print(
"sht30: crc check failed.\n");
1351 return a_sht30_write(handle, command);
1378 return a_sht30_read(handle, command, buf, len);
#define SHT30_COMMAND_READ_STATUS
#define SHT30_COMMAND_BREAK
#define SHT30_COMMAND_READ_HIGH_ALERT_LIMIT_CLEAR
#define SHT30_COMMAND_WRITE_HIGH_ALERT_LIMIT_CLEAR
#define SUPPLY_VOLTAGE_MAX
#define SHT30_COMMAND_READ_LOW_ALERT_LIMIT_CLEAR
#define SHT30_COMMAND_READ_HIGH_ALERT_LIMIT_SET
#define SHT30_COMMAND_SOFT_RESET
#define SHT30_COMMAND_GET_SERIAL_NUMBER
#define SHT30_COMMAND_FETCH_DATA
chip command definition
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define SHT30_COMMAND_WRITE_LOW_ALERT_LIMIT_CLEAR
#define SHT30_COMMAND_HEATER_DISABLE
#define SHT30_COMMAND_ART
#define SHT30_COMMAND_WRITE_LOW_ALERT_LIMIT_SET
#define CHIP_NAME
chip information definition
#define SHT30_COMMAND_HEATER_ENABLE
#define SHT30_COMMAND_READ_LOW_ALERT_LIMIT_SET
#define SHT30_COMMAND_WRITE_HIGH_ALERT_LIMIT_SET
#define SHT30_COMMAND_CLEAR_STATUS
uint8_t sht30_stop_continuous_read(sht30_handle_t *handle)
stop reading
uint8_t sht30_info(sht30_info_t *info)
get chip's information
uint8_t sht30_start_continuous_read(sht30_handle_t *handle, sht30_rate_t rate)
start reading
uint8_t sht30_set_repeatability(sht30_handle_t *handle, sht30_repeatability_t repeatability)
set the measurement repeatability
sht30_rate_t
sht30 rate enumeration definition
sht30_repeatability_t
sht30 repeatability enumeration definition
uint8_t sht30_get_addr_pin(sht30_handle_t *handle, sht30_address_t *addr_pin)
get the iic address pin
uint8_t sht30_single_read(sht30_handle_t *handle, sht30_bool_t clock_stretching_enable, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data once
uint8_t sht30_init(sht30_handle_t *handle)
initialize the chip
uint8_t sht30_soft_reset(sht30_handle_t *handle)
soft reset the chip
uint8_t sht30_get_low_alert_limit(sht30_handle_t *handle, uint16_t *set, uint16_t *clear)
get low alert limit
sht30_bool_t
sht30 bool enumeration definition
uint8_t sht30_set_art(sht30_handle_t *handle)
set the chip art
sht30_address_t
sht30 address enumeration definition
struct sht30_info_s sht30_info_t
sht30 information structure definition
uint8_t sht30_alert_limit_convert_to_register(sht30_handle_t *handle, float temperature, float humidity, uint16_t *reg)
alert limit convert to register raw data
uint8_t sht30_set_heater(sht30_handle_t *handle, sht30_bool_t enable)
enable or disable the chip heater
uint8_t sht30_get_status(sht30_handle_t *handle, uint16_t *status)
get the current status
uint8_t sht30_irq_handler(sht30_handle_t *handle)
irq handler
uint8_t sht30_set_addr_pin(sht30_handle_t *handle, sht30_address_t addr_pin)
set the iic address pin
uint8_t sht30_continuous_read(sht30_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data continuously
uint8_t sht30_set_high_alert_limit(sht30_handle_t *handle, uint16_t set, uint16_t clear)
set high alert limit
struct sht30_handle_s sht30_handle_t
sht30 handle structure definition
uint8_t sht30_get_high_alert_limit(sht30_handle_t *handle, uint16_t *set, uint16_t *clear)
get high alert limit
uint8_t sht30_get_repeatability(sht30_handle_t *handle, sht30_repeatability_t *repeatability)
get the measurement repeatability
uint8_t sht30_get_serial_number(sht30_handle_t *handle, uint8_t sn[4])
get serial number
uint8_t sht30_clear_status(sht30_handle_t *handle)
clear the current status
uint8_t sht30_set_low_alert_limit(sht30_handle_t *handle, uint16_t set, uint16_t clear)
set low alert limit
uint8_t sht30_deinit(sht30_handle_t *handle)
close the chip
@ SHT30_REPEATABILITY_MEDIUM
@ SHT30_REPEATABILITY_LOW
@ SHT30_REPEATABILITY_HIGH
@ SHT30_STATUS_ALERT_PENDING_STATUS
@ SHT30_STATUS_HUMIDITY_ALERT
@ SHT30_STATUS_TEMPERATURE_ALERT
uint8_t sht30_get_reg(sht30_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
get the chip register
uint8_t sht30_set_reg(sht30_handle_t *handle, uint16_t command)
set 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,...)
void(* receive_callback)(uint16_t type)
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