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");
264 res = a_sht30_write(handle, command);
267 handle->
debug_print(
"sht30: write command failed.\n");
273 handle->
debug_print(
"sht30: iic deinit failed.\n");
299 handle->
iic_addr = (uint8_t)addr_pin;
352 memset(data, 0,
sizeof(uint8_t) * 3);
354 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
357 handle->
debug_print(
"sht30: read status failed.\n");
361 if (a_sht30_crc((uint8_t *)data, 2) == data[2])
363 *status = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
400 res = a_sht30_write(handle, command);
403 handle->
debug_print(
"sht30: write command failed.\n");
479 uint16_t *temperature_raw,
float *temperature_s,
480 uint16_t *humidity_raw,
float *humidity_s
508 handle->
debug_print(
"sht30: clock stretching is invalid.\n");
525 handle->
debug_print(
"sht30: clock stretching is invalid.\n");
542 handle->
debug_print(
"sht30: clock stretching is invalid.\n");
549 handle->
debug_print(
"sht30: repeatability is invalid.\n");
553 memset(data, 0,
sizeof(uint8_t) * 6);
554 res = a_sht30_read(handle, command, (uint8_t *)data, 6);
561 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
567 if (a_sht30_crc((uint8_t *)&data[3], 2) != data[5])
573 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
574 *humidity_raw = (uint16_t)((((uint16_t)data[3]) << 8) | data[4]);
575 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f;
576 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f;
695 handle->
debug_print(
"sht30: repeatability is invalid.\n");
699 res = a_sht30_write(handle, command);
702 handle->
debug_print(
"sht30: write command failed.\n");
735 res = a_sht30_write(handle, command);
738 handle->
debug_print(
"sht30: write command failed.\n");
761 uint16_t *temperature_raw,
float *temperature_s,
762 uint16_t *humidity_raw,
float *humidity_s)
778 res = a_sht30_read(handle, command, (uint8_t *)data, 6);
785 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
791 if (a_sht30_crc((uint8_t *)&data[3], 2) != data[5])
797 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
798 *humidity_raw = (uint16_t)((((uint16_t)data[3]) << 8) | data[4]);
799 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f;
800 *humidity_s = (float)(*humidity_raw) / 65535.0f * 100.0f;
830 res = a_sht30_write(handle, command);
833 handle->
debug_print(
"sht30: write command failed.\n");
866 res = a_sht30_write(handle, command);
869 handle->
debug_print(
"sht30: write command failed.\n");
916 res = a_sht30_write(handle, command);
919 handle->
debug_print(
"sht30: write command failed.\n");
954 res = a_sht30_read(handle, command, (uint8_t *)data, 6);
961 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
967 if (a_sht30_crc((uint8_t *)&data[3], 2) != data[5])
1009 data[0] = (set >> 8) & 0xFF;
1010 data[1] = (set >> 0) & 0xFF;
1011 data[2] = a_sht30_crc((uint8_t *)data, 2);
1012 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1021 data[0] = (clear >> 8) & 0xFF;
1022 data[1] = (clear >> 0) & 0xFF;
1023 data[2] = a_sht30_crc((uint8_t *)data, 2);
1024 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1063 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1066 handle->
debug_print(
"sht30: read data failed.\n");
1070 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1072 handle->
debug_print(
"sht30: crc check failed.\n");
1076 *set = ((uint16_t)data[0] << 8) | data[1];
1079 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1082 handle->
debug_print(
"sht30: read data failed.\n");
1086 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1088 handle->
debug_print(
"sht30: crc check failed.\n");
1092 *clear = ((uint16_t)data[0] << 8) | data[1];
1125 data[0] = (set >> 8) & 0xFF;
1126 data[1] = (set >> 0) & 0xFF;
1127 data[2] = a_sht30_crc((uint8_t *)data, 2);
1128 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1137 data[0] = (clear >> 8) & 0xFF;
1138 data[1] = (clear >> 0) & 0xFF;
1139 data[2] = a_sht30_crc((uint8_t *)data, 2);
1140 res = a_sht30_write_bytes(handle, command, (uint8_t *)data, 3);
1179 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1182 handle->
debug_print(
"sht30: read data failed.\n");
1186 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1188 handle->
debug_print(
"sht30: crc check failed.\n");
1192 *set = ((uint16_t)data[0] << 8) | data[1];
1195 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1198 handle->
debug_print(
"sht30: read data failed.\n");
1202 if (a_sht30_crc((uint8_t *)data, 2) != data[2])
1204 handle->
debug_print(
"sht30: crc check failed.\n");
1208 *clear = ((uint16_t)data[0] << 8) | data[1];
1239 r_t = (uint16_t)(((temperature + 45.0f) / 175.0f) * 65535.0f);
1241 r_h = (uint16_t)((humidity / 100.0f) * 65535.0f);
1243 *reg = (r_h << 9) | r_t;
1274 memset(data, 0,
sizeof(uint8_t) * 3);
1276 res = a_sht30_read(handle, command, (uint8_t *)data, 3);
1279 handle->
debug_print(
"sht30: read status failed.\n");
1283 if (a_sht30_crc((uint8_t *)data, 2) == data[2])
1285 status = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
1287 res = a_sht30_write(handle, command);
1290 handle->
debug_print(
"sht30: write command failed.\n");
1321 handle->
debug_print(
"sht30: crc check failed.\n");
1349 return a_sht30_write(handle, command);
1376 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