LibDriver STS21
Loading...
Searching...
No Matches
driver_sts21_basic.c
Go to the documentation of this file.
1
36
37#include "driver_sts21_basic.h"
38
39static sts21_handle_t gs_handle;
40
48uint8_t sts21_basic_init(void)
49{
50 uint8_t res;
51
52 /* link functions */
64
65 /* sts21 init */
66 res = sts21_init(&gs_handle);
67 if (res != 0)
68 {
69 sts21_interface_debug_print("sts21: init failed.\n");
70
71 return 1;
72 }
73
74 /* set default heater */
76 if (res != 0)
77 {
78 sts21_interface_debug_print("sts21: set heater failed.\n");
79 (void)sts21_deinit(&gs_handle);
80
81 return 1;
82 }
83
84 /* set default disable otp reload */
86 if (res != 0)
87 {
88 sts21_interface_debug_print("sts21: set disable otp reload failed.\n");
89 (void)sts21_deinit(&gs_handle);
90
91 return 1;
92 }
93
94 /* set default mode */
96 if (res != 0)
97 {
98 sts21_interface_debug_print("sts21: set mode failed.\n");
99 (void)sts21_deinit(&gs_handle);
100
101 return 1;
102 }
103
104 /* set default resolution */
106 if (res != 0)
107 {
108 sts21_interface_debug_print("sts21: set resolution failed.\n");
109 (void)sts21_deinit(&gs_handle);
110
111 return 1;
112 }
113
114 return 0;
115}
116
125uint8_t sts21_basic_read(float *temperature)
126{
127 uint16_t temperature_raw;
128
129 /* read data */
130 if (sts21_read(&gs_handle, (uint16_t *)&temperature_raw, temperature) != 0)
131 {
132 return 1;
133 }
134
135 return 0;
136}
137
146{
147 /* close sts21 */
148 if (sts21_deinit(&gs_handle) != 0)
149 {
150 return 1;
151 }
152
153 return 0;
154}
155
164uint8_t sts21_basic_get_serial_number(uint8_t sn[8])
165{
166 /* get serial number */
167 if (sts21_get_serial_number(&gs_handle, sn) != 0)
168 {
169 return 1;
170 }
171
172 return 0;
173}
driver sts21 basic header file
uint8_t sts21_set_heater(sts21_handle_t *handle, sts21_bool_t enable)
enable or disable heater
uint8_t sts21_set_resolution(sts21_handle_t *handle, sts21_resolution_t resolution)
set resolution
uint8_t sts21_get_serial_number(sts21_handle_t *handle, uint8_t sn[8])
get serial number
uint8_t sts21_set_disable_otp_reload(sts21_handle_t *handle, sts21_bool_t enable)
enable or disable disable otp reload
struct sts21_handle_s sts21_handle_t
sts21 handle structure definition
uint8_t sts21_deinit(sts21_handle_t *handle)
close the chip
uint8_t sts21_set_mode(sts21_handle_t *handle, sts21_mode_t mode)
set chip mode
uint8_t sts21_init(sts21_handle_t *handle)
initialize the chip
uint8_t sts21_read(sts21_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read data
uint8_t sts21_basic_init(void)
basic example init
#define STS21_BASIC_DEFAULT_MODE
sts21 basic example default definition
#define STS21_BASIC_DEFAULT_RESOLUTION
#define STS21_BASIC_DEFAULT_HEATER
#define STS21_BASIC_DEFAULT_DISABLE_OTP_RELOAD
uint8_t sts21_basic_read(float *temperature)
basic example read
uint8_t sts21_basic_deinit(void)
basic example deinit
uint8_t sts21_basic_get_serial_number(uint8_t sn[8])
basic example get serial number
void sts21_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t sts21_interface_iic_init(void)
interface iic bus init
uint8_t sts21_interface_iic_read_command(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
uint8_t sts21_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t sts21_interface_iic_read_with_wait(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with wait
uint8_t sts21_interface_iic_deinit(void)
interface iic bus deinit
uint8_t sts21_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void sts21_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t sts21_interface_iic_write_command(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t sts21_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address