42#define CHIP_NAME "Sensirion STS3X"
43#define MANUFACTURER_NAME "Sensirion"
44#define SUPPLY_VOLTAGE_MIN 2.4f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 1.5f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
54#define STS3X_COMMAND_FETCH_DATA 0xE000U
55#define STS3X_COMMAND_BREAK 0x3093U
56#define STS3X_COMMAND_SOFT_RESET 0x30A2U
57#define STS3X_COMMAND_HEATER_ENABLE 0x306DU
58#define STS3X_COMMAND_HEATER_DISABLE 0x3066U
59#define STS3X_COMMAND_READ_STATUS 0xF32DU
60#define STS3X_COMMAND_CLEAR_STATUS 0x3041U
92static uint8_t a_sts3x_read(
sts3x_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len)
109static uint8_t a_sts3x_crc(uint8_t *data, uint16_t len)
111 const uint8_t POLYNOMIAL = 0x31;
115 for (j = len; j != 0; --j)
118 for (i = 8; i != 0; --i)
120 crc = (crc & 0x80) ? (crc << 1) ^ POLYNOMIAL : (crc<<1);
158 handle->
debug_print(
"sts3x: iic_deinit is null.\n");
164 handle->
debug_print(
"sts3x: iic_read_address16 is null.\n");
170 handle->
debug_print(
"sts3x: iic_write_address16 is null.\n");
188 res = a_sts3x_write(handle, command);
191 handle->
debug_print(
"sts3x: write command failed.\n");
227 res = a_sts3x_write(handle, command);
230 handle->
debug_print(
"sts3x: write command failed.\n");
236 handle->
debug_print(
"sts3x: iic deinit failed.\n");
262 handle->
iic_addr = (uint8_t)addr_pin;
314 memset(data, 0,
sizeof(uint8_t) * 3);
316 res = a_sts3x_read(handle, command, (uint8_t *)data, 3);
319 handle->
debug_print(
"sts3x: read status failed.\n");
323 if (a_sts3x_crc((uint8_t *)data, 2) == data[2])
325 *status = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
361 res = a_sts3x_write(handle, command);
364 handle->
debug_print(
"sts3x: write command failed.\n");
438 uint16_t *temperature_raw,
float *temperature_s)
465 handle->
debug_print(
"sts3x: clock stretching is invalid.\n");
482 handle->
debug_print(
"sts3x: clock stretching is invalid.\n");
499 handle->
debug_print(
"sts3x: clock stretching is invalid.\n");
506 handle->
debug_print(
"sts3x: repeatability is invalid.\n");
510 memset(data, 0,
sizeof(uint8_t) * 3);
511 res = a_sts3x_read(handle, command, (uint8_t *)data, 3);
518 if (a_sts3x_crc((uint8_t *)data, 2) != data[2])
524 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
525 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f;
644 handle->
debug_print(
"sts3x: repeatability is invalid.\n");
648 res = a_sts3x_write(handle, command);
651 handle->
debug_print(
"sts3x: write command failed.\n");
684 res = a_sts3x_write(handle, command);
687 handle->
debug_print(
"sts3x: write command failed.\n");
723 res = a_sts3x_read(handle, command, (uint8_t *)data, 3);
730 if (a_sts3x_crc((uint8_t *)data, 2) != data[2])
736 *temperature_raw = (uint16_t)((((uint16_t)data[0]) << 8) | data[1]);
737 *temperature_s = (float)(*temperature_raw) / 65535.0f * 175.0f - 45.0f;
767 res = a_sts3x_write(handle, command);
770 handle->
debug_print(
"sts3x: write command failed.\n");
818 res = a_sts3x_write(handle, command);
821 handle->
debug_print(
"sts3x: write command failed.\n");
851 return a_sts3x_write(handle, command);
878 return a_sts3x_read(handle, command, buf, len);
#define STS3X_COMMAND_READ_STATUS
#define STS3X_COMMAND_BREAK
#define SUPPLY_VOLTAGE_MAX
#define STS3X_COMMAND_SOFT_RESET
#define STS3X_COMMAND_CLEAR_STATUS
#define STS3X_COMMAND_FETCH_DATA
chip command definition
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define STS3X_COMMAND_HEATER_ENABLE
#define CHIP_NAME
chip information definition
#define STS3X_COMMAND_HEATER_DISABLE
uint8_t sts3x_set_addr_pin(sts3x_handle_t *handle, sts3x_address_t addr_pin)
set the iic address pin
uint8_t sts3x_get_repeatability(sts3x_handle_t *handle, sts3x_repeatability_t *repeatability)
get the measurement repeatability
uint8_t sts3x_clear_status(sts3x_handle_t *handle)
clear the current status
sts3x_address_t
sts3x address enumeration definition
uint8_t sts3x_set_repeatability(sts3x_handle_t *handle, sts3x_repeatability_t repeatability)
set the measurement repeatability
sts3x_rate_t
sts3x rate enumeration definition
uint8_t sts3x_continuous_read(sts3x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read data continuously
uint8_t sts3x_soft_reset(sts3x_handle_t *handle)
soft reset the chip
uint8_t sts3x_info(sts3x_info_t *info)
get chip's information
struct sts3x_handle_s sts3x_handle_t
sts3x handle structure definition
uint8_t sts3x_start_continuous_read(sts3x_handle_t *handle, sts3x_rate_t rate)
start reading
uint8_t sts3x_get_addr_pin(sts3x_handle_t *handle, sts3x_address_t *addr_pin)
get the iic address pin
uint8_t sts3x_init(sts3x_handle_t *handle)
initialize the chip
struct sts3x_info_s sts3x_info_t
sts3x information structure definition
uint8_t sts3x_set_heater(sts3x_handle_t *handle, sts3x_bool_t enable)
enable or disable the chip heater
sts3x_repeatability_t
sts3x repeatability enumeration definition
uint8_t sts3x_get_status(sts3x_handle_t *handle, uint16_t *status)
get the current status
uint8_t sts3x_stop_continuous_read(sts3x_handle_t *handle)
stop reading
uint8_t sts3x_deinit(sts3x_handle_t *handle)
close the chip
uint8_t sts3x_single_read(sts3x_handle_t *handle, sts3x_bool_t clock_stretching_enable, uint16_t *temperature_raw, float *temperature_s)
read data once
sts3x_bool_t
sts3x bool enumeration definition
@ STS3X_REPEATABILITY_HIGH
@ STS3X_REPEATABILITY_MEDIUM
@ STS3X_REPEATABILITY_LOW
uint8_t sts3x_set_reg(sts3x_handle_t *handle, uint16_t command)
set the chip register
uint8_t sts3x_get_reg(sts3x_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