LibDriver SHT85
Loading...
Searching...
No Matches
driver_sht85_register_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static sht85_handle_t gs_handle;
41
50{
51 uint8_t res;
52 uint16_t status;
53 uint8_t sn[4];
54 sht85_info_t info;
55 sht85_repeatability_t repeatability;
56
57 /* link functions */
65
66 /* sht85 info */
67 res = sht85_info(&info);
68 if (res != 0)
69 {
70 sht85_interface_debug_print("sht85: get info failed.\n");
71
72 return 1;
73 }
74 else
75 {
76 /* print chip information */
77 sht85_interface_debug_print("sht85: chip is %s.\n", info.chip_name);
78 sht85_interface_debug_print("sht85: manufacturer is %s.\n", info.manufacturer_name);
79 sht85_interface_debug_print("sht85: interface is %s.\n", info.interface);
80 sht85_interface_debug_print("sht85: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
81 sht85_interface_debug_print("sht85: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
82 sht85_interface_debug_print("sht85: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
83 sht85_interface_debug_print("sht85: max current is %0.2fmA.\n", info.max_current_ma);
84 sht85_interface_debug_print("sht85: max temperature is %0.1fC.\n", info.temperature_max);
85 sht85_interface_debug_print("sht85: min temperature is %0.1fC.\n", info.temperature_min);
86 }
87
88 /* start register test */
89 sht85_interface_debug_print("sht85: start register test.\n");
90
91 /* sht85 init */
92 res = sht85_init(&gs_handle);
93 if (res != 0)
94 {
95 sht85_interface_debug_print("sht85: init failed.\n");
96
97 return 1;
98 }
99
100 /* wait 10 ms */
102
103 /* sht85_set_repeatability/sht85_get_repeatability test */
104 sht85_interface_debug_print("sht85: sht85_set_repeatability/sht85_get_repeatability test.\n");
105
106 /* set high */
108 if (res != 0)
109 {
110 sht85_interface_debug_print("sht85: set repeatability failed.\n");
111 (void)sht85_deinit(&gs_handle);
112
113 return 1;
114 }
115 sht85_interface_debug_print("sht85: set repeatability high.\n");
116 res = sht85_get_repeatability(&gs_handle, &repeatability);
117 if (res != 0)
118 {
119 sht85_interface_debug_print("sht85: get repeatability failed.\n");
120 (void)sht85_deinit(&gs_handle);
121
122 return 1;
123 }
124 sht85_interface_debug_print("sht85: check repeatability pin %s.\n", (SHT85_REPEATABILITY_HIGH == repeatability) ? "ok" : "error");
125
126 /* set medium */
128 if (res != 0)
129 {
130 sht85_interface_debug_print("sht85: set repeatability failed.\n");
131 (void)sht85_deinit(&gs_handle);
132
133 return 1;
134 }
135 sht85_interface_debug_print("sht85: set repeatability medium.\n");
136 res = sht85_get_repeatability(&gs_handle, &repeatability);
137 if (res != 0)
138 {
139 sht85_interface_debug_print("sht85: get repeatability failed.\n");
140 (void)sht85_deinit(&gs_handle);
141
142 return 1;
143 }
144 sht85_interface_debug_print("sht85: check repeatability pin %s.\n", (SHT85_REPEATABILITY_MEDIUM == repeatability) ? "ok" : "error");
145
146 /* set low */
148 if (res != 0)
149 {
150 sht85_interface_debug_print("sht85: set repeatability failed.\n");
151 (void)sht85_deinit(&gs_handle);
152
153 return 1;
154 }
155 sht85_interface_debug_print("sht85: set repeatability low.\n");
156 res = sht85_get_repeatability(&gs_handle, &repeatability);
157 if (res != 0)
158 {
159 sht85_interface_debug_print("sht85: get repeatability failed.\n");
160 (void)sht85_deinit(&gs_handle);
161
162 return 1;
163 }
164 sht85_interface_debug_print("sht85: check repeatability pin %s.\n", (SHT85_REPEATABILITY_LOW == repeatability) ? "ok" : "error");
165
166 /* set art test */
167 sht85_interface_debug_print("sht85: set art test.\n");
168 res = sht85_set_art(&gs_handle);
169 if (res != 0)
170 {
171 sht85_interface_debug_print("sht85: set art failed.\n");
172 (void)sht85_deinit(&gs_handle);
173
174 return 1;
175 }
176
177 /* wait 10 ms */
179 sht85_interface_debug_print("sht85: check art %s.\n", (res == 0) ? "ok" : "error");
180
181 /* sht85_set_heater test*/
182 sht85_interface_debug_print("sht85: set heater test.\n");
183
184 /* enable heater */
185 res = sht85_set_heater(&gs_handle, SHT85_BOOL_TRUE);
186 if (res != 0)
187 {
188 sht85_interface_debug_print("sht85: set heater failed.\n");
189 (void)sht85_deinit(&gs_handle);
190
191 return 1;
192 }
193
194 /* wait 10 ms */
196 sht85_interface_debug_print("sht85: enable heater.\n");
197 sht85_interface_debug_print("sht85: check heater %s.\n", (res == 0) ? "ok" : "error");
198
199 /* disable heater */
200 res = sht85_set_heater(&gs_handle, SHT85_BOOL_FALSE);
201 if (res != 0)
202 {
203 sht85_interface_debug_print("sht85: set heater failed.\n");
204 (void)sht85_deinit(&gs_handle);
205
206 return 1;
207 }
208
209 /* wait 10 ms */
211 sht85_interface_debug_print("sht85: disable heater.\n");
212 sht85_interface_debug_print("sht85: check heater %s.\n", (res == 0) ? "ok" : "error");
213
214 /* get_status test*/
215 sht85_interface_debug_print("sht85: sht85_get_status test.\n");
216 res = sht85_get_status(&gs_handle, (uint16_t *)&status);
217 if (res != 0)
218 {
219 sht85_interface_debug_print("sht85: get status failed.\n");
220 (void)sht85_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* wait 10 ms */
227 sht85_interface_debug_print("sht85: check status 0x%02X.\n", status);
228
229 /* clear_status test*/
230 sht85_interface_debug_print("sht85: sht85_clear_status test.\n");
231 res = sht85_clear_status(&gs_handle);
232 if (res != 0)
233 {
234 sht85_interface_debug_print("sht85: clear status failed.\n");
235 (void)sht85_deinit(&gs_handle);
236
237 return 1;
238 }
239
240 /* wait 10 ms */
242 sht85_interface_debug_print("sht85: check clear status %s.\n", (res == 0) ? "ok" : "error");
243
244 /* sht85_get_serial_number test*/
245 sht85_interface_debug_print("sht85: sht85_get_serial_number test.\n");
246
247 /* get serial number */
248 res = sht85_get_serial_number(&gs_handle, sn);
249 if (res != 0)
250 {
251 sht85_interface_debug_print("sht85: get serial number failed.\n");
252 (void)sht85_deinit(&gs_handle);
253
254 return 1;
255 }
256 sht85_interface_debug_print("sht85: serial number is 0x%02X 0x%02X 0x%02X 0x%02X.\n", sn[0], sn[1], sn[2], sn[3]);
257
258 /* finish register test */
259 sht85_interface_debug_print("sht85: finish register test.\n");
260 (void)sht85_deinit(&gs_handle);
261
262 return 0;
263}
driver sht85 register test header file
uint8_t sht85_set_heater(sht85_handle_t *handle, sht85_bool_t enable)
enable or disable the chip heater
uint8_t sht85_clear_status(sht85_handle_t *handle)
clear the current status
uint8_t sht85_get_serial_number(sht85_handle_t *handle, uint8_t sn[4])
get serial number
struct sht85_info_s sht85_info_t
sht85 information structure definition
uint8_t sht85_init(sht85_handle_t *handle)
initialize the chip
uint8_t sht85_set_repeatability(sht85_handle_t *handle, sht85_repeatability_t repeatability)
set the measurement repeatability
sht85_repeatability_t
sht85 repeatability enumeration definition
uint8_t sht85_deinit(sht85_handle_t *handle)
close the chip
uint8_t sht85_info(sht85_info_t *info)
get chip's information
uint8_t sht85_set_art(sht85_handle_t *handle)
set the chip art
uint8_t sht85_get_status(sht85_handle_t *handle, uint16_t *status)
get the current status
struct sht85_handle_s sht85_handle_t
sht85 handle structure definition
uint8_t sht85_get_repeatability(sht85_handle_t *handle, sht85_repeatability_t *repeatability)
get the measurement repeatability
@ SHT85_REPEATABILITY_HIGH
@ SHT85_REPEATABILITY_LOW
@ SHT85_REPEATABILITY_MEDIUM
@ SHT85_BOOL_TRUE
@ SHT85_BOOL_FALSE
uint8_t sht85_interface_iic_deinit(void)
interface iic bus deinit
uint8_t sht85_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
void sht85_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t sht85_interface_iic_init(void)
interface iic bus init
uint8_t sht85_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write with 16 bits register address
void sht85_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t sht85_register_test(void)
register test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]