43#define CHIP_NAME "Sensirion SHT35"
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 SHT35_COMMAND_FETCH_DATA 0xE000U
56#define SHT35_COMMAND_ART 0x2B32U
57#define SHT35_COMMAND_BREAK 0x3093U
58#define SHT35_COMMAND_SOFT_RESET 0x30A2U
59#define SHT35_COMMAND_HEATER_ENABLE 0x306DU
60#define SHT35_COMMAND_HEATER_DISABLE 0x3066U
61#define SHT35_COMMAND_READ_STATUS 0xF32DU
62#define SHT35_COMMAND_CLEAR_STATUS 0x3041U
63#define SHT35_COMMAND_GET_SERIAL_NUMBER 0x3682U
64#define SHT35_COMMAND_READ_HIGH_ALERT_LIMIT_SET 0xE11FU
65#define SHT35_COMMAND_READ_HIGH_ALERT_LIMIT_CLEAR 0xE114U
66#define SHT35_COMMAND_READ_LOW_ALERT_LIMIT_SET 0xE102U
67#define SHT35_COMMAND_READ_LOW_ALERT_LIMIT_CLEAR 0xE109U
68#define SHT35_COMMAND_WRITE_HIGH_ALERT_LIMIT_SET 0x611DU
69#define SHT35_COMMAND_WRITE_HIGH_ALERT_LIMIT_CLEAR 0x6116U
70#define SHT35_COMMAND_WRITE_LOW_ALERT_LIMIT_SET 0x6100U
71#define SHT35_COMMAND_WRITE_LOW_ALERT_LIMIT_CLEAR 0x610BU
105static uint8_t a_sht35_write_bytes(
sht35_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len)
128static uint8_t a_sht35_read(
sht35_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len)
147static uint8_t a_sht35_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(
"sht35: iic_deinit is null.\n");
202 handle->
debug_print(
"sht35: iic_read_address16 is null.\n");
208 handle->
debug_print(
"sht35: iic_write_address16 is null.\n");
226 res = a_sht35_write(handle, command);
229 handle->
debug_print(
"sht35: write command failed.\n");
265 res = a_sht35_write(handle, command);
268 handle->
debug_print(
"sht35: write command failed.\n");
274 handle->
debug_print(
"sht35: iic deinit failed.\n");
300 handle->
iic_addr = (uint8_t)addr_pin;
353 memset(data, 0,
sizeof(uint8_t) * 3);
355 res = a_sht35_read(handle, command, (uint8_t *)data, 3);
358 handle->
debug_print(
"sht35: read status failed.\n");
362 if (a_sht35_crc((uint8_t *)data, 2) == data[2])
364 *status = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
401 res = a_sht35_write(handle, command);
404 handle->
debug_print(
"sht35: write command failed.\n");
480 uint16_t *temperature_raw,
float *temperature_s,
481 uint16_t *humidity_raw,
float *humidity_s
509 handle->
debug_print(
"sht35: clock stretching is invalid.\n");
526 handle->
debug_print(
"sht35: clock stretching is invalid.\n");
543 handle->
debug_print(
"sht35: clock stretching is invalid.\n");
550 handle->
debug_print(
"sht35: repeatability is invalid.\n");
554 memset(data, 0,
sizeof(uint8_t) * 6);
555 res = a_sht35_read(handle, command, (uint8_t *)data, 6);
562 if (a_sht35_crc((uint8_t *)data, 2) != data[2])
568 if (a_sht35_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(
"sht35: repeatability is invalid.\n");
700 res = a_sht35_write(handle, command);
703 handle->
debug_print(
"sht35: write command failed.\n");
736 res = a_sht35_write(handle, command);
739 handle->
debug_print(
"sht35: write command failed.\n");
762 uint16_t *temperature_raw,
float *temperature_s,
763 uint16_t *humidity_raw,
float *humidity_s)
779 res = a_sht35_read(handle, command, (uint8_t *)data, 6);
786 if (a_sht35_crc((uint8_t *)data, 2) != data[2])
792 if (a_sht35_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_sht35_write(handle, command);
834 handle->
debug_print(
"sht35: write command failed.\n");
867 res = a_sht35_write(handle, command);
870 handle->
debug_print(
"sht35: write command failed.\n");
918 res = a_sht35_write(handle, command);
921 handle->
debug_print(
"sht35: write command failed.\n");
956 res = a_sht35_read(handle, command, (uint8_t *)data, 6);
963 if (a_sht35_crc((uint8_t *)data, 2) != data[2])
969 if (a_sht35_crc((uint8_t *)&data[3], 2) != data[5])
1011 data[0] = (set >> 8) & 0xFF;
1012 data[1] = (set >> 0) & 0xFF;
1013 data[2] = a_sht35_crc((uint8_t *)data, 2);
1014 res = a_sht35_write_bytes(handle, command, (uint8_t *)data, 3);
1023 data[0] = (clear >> 8) & 0xFF;
1024 data[1] = (clear >> 0) & 0xFF;
1025 data[2] = a_sht35_crc((uint8_t *)data, 2);
1026 res = a_sht35_write_bytes(handle, command, (uint8_t *)data, 3);
1065 res = a_sht35_read(handle, command, (uint8_t *)data, 3);
1068 handle->
debug_print(
"sht35: read data failed.\n");
1072 if (a_sht35_crc((uint8_t *)data, 2) != data[2])
1074 handle->
debug_print(
"sht35: crc check failed.\n");
1078 *set = ((uint16_t)data[0] << 8) | data[1];
1081 res = a_sht35_read(handle, command, (uint8_t *)data, 3);
1084 handle->
debug_print(
"sht35: read data failed.\n");
1088 if (a_sht35_crc((uint8_t *)data, 2) != data[2])
1090 handle->
debug_print(
"sht35: 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_sht35_crc((uint8_t *)data, 2);
1130 res = a_sht35_write_bytes(handle, command, (uint8_t *)data, 3);
1139 data[0] = (clear >> 8) & 0xFF;
1140 data[1] = (clear >> 0) & 0xFF;
1141 data[2] = a_sht35_crc((uint8_t *)data, 2);
1142 res = a_sht35_write_bytes(handle, command, (uint8_t *)data, 3);
1181 res = a_sht35_read(handle, command, (uint8_t *)data, 3);
1184 handle->
debug_print(
"sht35: read data failed.\n");
1188 if (a_sht35_crc((uint8_t *)data, 2) != data[2])
1190 handle->
debug_print(
"sht35: crc check failed.\n");
1194 *set = ((uint16_t)data[0] << 8) | data[1];
1197 res = a_sht35_read(handle, command, (uint8_t *)data, 3);
1200 handle->
debug_print(
"sht35: read data failed.\n");
1204 if (a_sht35_crc((uint8_t *)data, 2) != data[2])
1206 handle->
debug_print(
"sht35: 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_sht35_read(handle, command, (uint8_t *)data, 3);
1281 handle->
debug_print(
"sht35: read status failed.\n");
1285 if (a_sht35_crc((uint8_t *)data, 2) == data[2])
1287 status = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
1289 res = a_sht35_write(handle, command);
1292 handle->
debug_print(
"sht35: write command failed.\n");
1323 handle->
debug_print(
"sht35: crc check failed.\n");
1351 return a_sht35_write(handle, command);
1378 return a_sht35_read(handle, command, buf, len);
#define SHT35_COMMAND_READ_LOW_ALERT_LIMIT_CLEAR
#define SHT35_COMMAND_ART
#define SHT35_COMMAND_WRITE_LOW_ALERT_LIMIT_SET
#define SHT35_COMMAND_WRITE_HIGH_ALERT_LIMIT_CLEAR
#define SHT35_COMMAND_HEATER_ENABLE
#define SUPPLY_VOLTAGE_MAX
#define SHT35_COMMAND_FETCH_DATA
chip command definition
#define SHT35_COMMAND_BREAK
#define SHT35_COMMAND_SOFT_RESET
#define SHT35_COMMAND_CLEAR_STATUS
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define SHT35_COMMAND_READ_LOW_ALERT_LIMIT_SET
#define SHT35_COMMAND_READ_HIGH_ALERT_LIMIT_SET
#define SHT35_COMMAND_GET_SERIAL_NUMBER
#define SHT35_COMMAND_READ_HIGH_ALERT_LIMIT_CLEAR
#define CHIP_NAME
chip information definition
#define SHT35_COMMAND_WRITE_HIGH_ALERT_LIMIT_SET
#define SHT35_COMMAND_READ_STATUS
#define SHT35_COMMAND_WRITE_LOW_ALERT_LIMIT_CLEAR
#define SHT35_COMMAND_HEATER_DISABLE
uint8_t sht35_set_repeatability(sht35_handle_t *handle, sht35_repeatability_t repeatability)
set the measurement repeatability
uint8_t sht35_info(sht35_info_t *info)
get chip's information
uint8_t sht35_get_high_alert_limit(sht35_handle_t *handle, uint16_t *set, uint16_t *clear)
get high alert limit
uint8_t sht35_get_low_alert_limit(sht35_handle_t *handle, uint16_t *set, uint16_t *clear)
get low alert limit
uint8_t sht35_deinit(sht35_handle_t *handle)
close the chip
uint8_t sht35_alert_limit_convert_to_register(sht35_handle_t *handle, float temperature, float humidity, uint16_t *reg)
alert limit convert to register raw data
uint8_t sht35_stop_continuous_read(sht35_handle_t *handle)
stop reading
uint8_t sht35_init(sht35_handle_t *handle)
initialize the chip
uint8_t sht35_clear_status(sht35_handle_t *handle)
clear the current status
sht35_address_t
sht35 address enumeration definition
uint8_t sht35_soft_reset(sht35_handle_t *handle)
soft reset the chip
sht35_rate_t
sht35 rate enumeration definition
uint8_t sht35_get_addr_pin(sht35_handle_t *handle, sht35_address_t *addr_pin)
get the iic address pin
sht35_repeatability_t
sht35 repeatability enumeration definition
uint8_t sht35_continuous_read(sht35_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data continuously
uint8_t sht35_single_read(sht35_handle_t *handle, sht35_bool_t clock_stretching_enable, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data once
uint8_t sht35_get_serial_number(sht35_handle_t *handle, uint8_t sn[4])
get serial number
uint8_t sht35_get_status(sht35_handle_t *handle, uint16_t *status)
get the current status
uint8_t sht35_set_heater(sht35_handle_t *handle, sht35_bool_t enable)
enable or disable the chip heater
struct sht35_info_s sht35_info_t
sht35 information structure definition
uint8_t sht35_start_continuous_read(sht35_handle_t *handle, sht35_rate_t rate)
start reading
uint8_t sht35_set_low_alert_limit(sht35_handle_t *handle, uint16_t set, uint16_t clear)
set low alert limit
struct sht35_handle_s sht35_handle_t
sht35 handle structure definition
uint8_t sht35_irq_handler(sht35_handle_t *handle)
irq handler
uint8_t sht35_get_repeatability(sht35_handle_t *handle, sht35_repeatability_t *repeatability)
get the measurement repeatability
uint8_t sht35_set_high_alert_limit(sht35_handle_t *handle, uint16_t set, uint16_t clear)
set high alert limit
sht35_bool_t
sht35 bool enumeration definition
uint8_t sht35_set_art(sht35_handle_t *handle)
set the chip art
uint8_t sht35_set_addr_pin(sht35_handle_t *handle, sht35_address_t addr_pin)
set the iic address pin
@ SHT35_STATUS_HUMIDITY_ALERT
@ SHT35_STATUS_TEMPERATURE_ALERT
@ SHT35_STATUS_ALERT_PENDING_STATUS
@ SHT35_REPEATABILITY_MEDIUM
@ SHT35_REPEATABILITY_LOW
@ SHT35_REPEATABILITY_HIGH
uint8_t sht35_set_reg(sht35_handle_t *handle, uint16_t command)
set the chip register
uint8_t sht35_get_reg(sht35_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,...)
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