LibDriver HDC2080
Loading...
Searching...
No Matches
driver_hdc2080_interrupt_test.c
Go to the documentation of this file.
1
36
38
39static hdc2080_handle_t gs_handle;
40
54uint8_t hdc2080_interrupt_test(hdc2080_address_t addr_pin, float high_deg, float low_deg,
55 float high_percent, float low_percent, uint32_t times)
56{
57 uint8_t res;
58 uint8_t reg;
59 int8_t offset;
60 uint32_t i = 0;
61 hdc2080_info_t info;
62
63 /* link interface function */
71
72 /* get hdc2080 information */
73 res = hdc2080_info(&info);
74 if (res != 0)
75 {
76 hdc2080_interface_debug_print("hdc2080: get info failed.\n");
77
78 return 1;
79 }
80 else
81 {
82 /* print hdc2080 information */
83 hdc2080_interface_debug_print("hdc2080: chip is %s.\n", info.chip_name);
84 hdc2080_interface_debug_print("hdc2080: manufacturer is %s.\n", info.manufacturer_name);
85 hdc2080_interface_debug_print("hdc2080: interface is %s.\n", info.interface);
86 hdc2080_interface_debug_print("hdc2080: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87 hdc2080_interface_debug_print("hdc2080: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88 hdc2080_interface_debug_print("hdc2080: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89 hdc2080_interface_debug_print("hdc2080: max current is %0.2fmA.\n", info.max_current_ma);
90 hdc2080_interface_debug_print("hdc2080: max temperature is %0.1fC.\n", info.temperature_max);
91 hdc2080_interface_debug_print("hdc2080: min temperature is %0.1fC.\n", info.temperature_min);
92 }
93
94 /* start interrupt test */
95 hdc2080_interface_debug_print("hdc2080: start interrupt test.\n");
96
97 /* set addr pin */
98 res = hdc2080_set_addr_pin(&gs_handle, addr_pin);
99 if (res != 0)
100 {
101 hdc2080_interface_debug_print("hdc2080: set addr pin failed.\n");
102
103 return 1;
104 }
105
106 /* hdc2080 init */
107 res = hdc2080_init(&gs_handle);
108 if (res != 0)
109 {
110 hdc2080_interface_debug_print("hdc2080: init failed.\n");
111
112 return 1;
113 }
114
115 /* set temperature resolution 14bits */
117 if (res != 0)
118 {
119 hdc2080_interface_debug_print("hdc2080: set temperature resolution failed.\n");
120 (void)hdc2080_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* set humidity resolution 14bits */
127 if (res != 0)
128 {
129 hdc2080_interface_debug_print("hdc2080: set humidity resolution failed.\n");
130 (void)hdc2080_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* set humidity and temperature */
137 if (res != 0)
138 {
139 hdc2080_interface_debug_print("hdc2080: set mode failed.\n");
140 (void)hdc2080_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* disable heater */
146 res = hdc2080_set_heater(&gs_handle, HDC2080_BOOL_FALSE);
147 if (res != 0)
148 {
149 hdc2080_interface_debug_print("hdc2080: set heater failed.\n");
150 (void)hdc2080_deinit(&gs_handle);
151
152 return 1;
153 }
154
155 /* enable interrupt pin */
157 if (res != 0)
158 {
159 hdc2080_interface_debug_print("hdc2080: set interrupt pin failed.\n");
160 (void)hdc2080_deinit(&gs_handle);
161
162 return 1;
163 }
164
165 /* set interrupt polarity low */
167 if (res != 0)
168 {
169 hdc2080_interface_debug_print("hdc2080: set interrupt polarity failed.\n");
170 (void)hdc2080_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* set comparator mode */
177 if (res != 0)
178 {
179 hdc2080_interface_debug_print("hdc2080: set interrupt mode failed.\n");
180 (void)hdc2080_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* set high threshold */
186 res = hdc2080_humidity_convert_to_register(&gs_handle, high_percent, &reg);
187 if (res != 0)
188 {
189 hdc2080_interface_debug_print("hdc2080: humidity convert to register failed.\n");
190 (void)hdc2080_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* set humidity high threshold */
196 res = hdc2080_set_humidity_high_threshold(&gs_handle, reg);
197 if (res != 0)
198 {
199 hdc2080_interface_debug_print("hdc2080: set humidity high threshold failed.\n");
200 (void)hdc2080_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* set low threshold */
206 res = hdc2080_humidity_convert_to_register(&gs_handle, low_percent, &reg);
207 if (res != 0)
208 {
209 hdc2080_interface_debug_print("hdc2080: humidity convert to register failed.\n");
210 (void)hdc2080_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* set humidity low threshold */
216 res = hdc2080_set_humidity_low_threshold(&gs_handle, reg);
217 if (res != 0)
218 {
219 hdc2080_interface_debug_print("hdc2080: set humidity low threshold failed.\n");
220 (void)hdc2080_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* set high threshold */
226 res = hdc2080_temperature_convert_to_register(&gs_handle, high_deg, &reg);
227 if (res != 0)
228 {
229 hdc2080_interface_debug_print("hdc2080: temperature convert to register failed.\n");
230 (void)hdc2080_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* set temperature high threshold */
236 res = hdc2080_set_temperature_high_threshold(&gs_handle, reg);
237 if (res != 0)
238 {
239 hdc2080_interface_debug_print("hdc2080: set temperature high threshold failed.\n");
240 (void)hdc2080_deinit(&gs_handle);
241
242 return 1;
243 }
244
245 /* set low threshold */
246 res = hdc2080_temperature_convert_to_register(&gs_handle, low_deg, &reg);
247 if (res != 0)
248 {
249 hdc2080_interface_debug_print("hdc2080: temperature convert to register failed.\n");
250 (void)hdc2080_deinit(&gs_handle);
251
252 return 1;
253 }
254
255 /* set temperature low threshold */
256 res = hdc2080_set_temperature_low_threshold(&gs_handle, reg);
257 if (res != 0)
258 {
259 hdc2080_interface_debug_print("hdc2080: set temperature low threshold failed.\n");
260 (void)hdc2080_deinit(&gs_handle);
261
262 return 1;
263 }
264
265 /* 0.0 */
266 res = hdc2080_humidity_offset_convert_to_register(&gs_handle, 0.0f, &offset);
267 if (res != 0)
268 {
269 hdc2080_interface_debug_print("hdc2080: humidity offset convert to register failed.\n");
270 (void)hdc2080_deinit(&gs_handle);
271
272 return 1;
273 }
274
275 /* set humidity offset adjustment */
276 res = hdc2080_set_humidity_offset_adjustment(&gs_handle, offset);
277 if (res != 0)
278 {
279 hdc2080_interface_debug_print("hdc2080: set humidity offset adjustment failed.\n");
280 (void)hdc2080_deinit(&gs_handle);
281
282 return 1;
283 }
284
285 /* 0.0 */
286 res = hdc2080_temperature_offset_convert_to_register(&gs_handle, 0.0f, &offset);
287 if (res != 0)
288 {
289 hdc2080_interface_debug_print("hdc2080: temperature offset convert to register failed.\n");
290 (void)hdc2080_deinit(&gs_handle);
291
292 return 1;
293 }
294
295 /* set temperature offset adjustment */
296 res = hdc2080_set_temperature_offset_adjustment(&gs_handle, offset);
297 if (res != 0)
298 {
299 hdc2080_interface_debug_print("hdc2080: set temperature offset adjustment failed.\n");
300 (void)hdc2080_deinit(&gs_handle);
301
302 return 1;
303 }
304
305 /* disable data ready */
307 if (res != 0)
308 {
309 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
310 (void)hdc2080_deinit(&gs_handle);
311
312 return 1;
313 }
314
315 /* enable temperature high threshold */
317 if (res != 0)
318 {
319 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
320 (void)hdc2080_deinit(&gs_handle);
321
322 return 1;
323 }
324
325 /* enable temperature low threshold */
327 if (res != 0)
328 {
329 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
330 (void)hdc2080_deinit(&gs_handle);
331
332 return 1;
333 }
334
335 /* enable humidity high threshold */
337 if (res != 0)
338 {
339 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
340 (void)hdc2080_deinit(&gs_handle);
341
342 return 1;
343 }
344
345 /* enable humidity low threshold */
347 if (res != 0)
348 {
349 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
350 (void)hdc2080_deinit(&gs_handle);
351
352 return 1;
353 }
354
355 /* disable auto measurement mode */
357 if (res != 0)
358 {
359 hdc2080_interface_debug_print("hdc2080: set auto measurement mode failed.\n");
360 (void)hdc2080_deinit(&gs_handle);
361
362 return 1;
363 }
364
365 /* loop */
366 for (i = 0; i < times; i++)
367 {
368 uint16_t temperature_raw;
369 float temperature_s;
370 uint16_t humidity_raw;
371 float humidity_s;
372
373 /* read poll */
374 res = hdc2080_read_poll(&gs_handle);
375 if (res != 0)
376 {
377 hdc2080_interface_debug_print("hdc2080: read poll failed.\n");
378 (void)hdc2080_deinit(&gs_handle);
379
380 return 1;
381 }
382
383 /* read temperature humidity */
384 res = hdc2080_read_temperature_humidity(&gs_handle, &temperature_raw, &temperature_s, &humidity_raw, &humidity_s);
385 if (res != 0)
386 {
387 hdc2080_interface_debug_print("hdc2080: read temperature humidity failed.\n");
388 (void)hdc2080_deinit(&gs_handle);
389
390 return 1;
391 }
392
393 /* output */
394 hdc2080_interface_debug_print("hdc2080: temperature[%d] is %0.2fC.\n", i, temperature_s);
395 hdc2080_interface_debug_print("hdc2080: humidity[%d] is %0.2f%%.\n", i, humidity_s);
396 if (temperature_s > high_deg)
397 {
398 hdc2080_interface_debug_print("hdc2080: temperature is over high threshold and check the interrupt pin.\n");
399 }
400 if (temperature_s < low_deg)
401 {
402 hdc2080_interface_debug_print("hdc2080: temperature is less than low threshold and check the interrupt pin.\n");
403 }
404 if (humidity_s > high_percent)
405 {
406 hdc2080_interface_debug_print("hdc2080: humidity is over high threshold and check the interrupt pin.\n");
407 }
408 if (humidity_s < low_percent)
409 {
410 hdc2080_interface_debug_print("hdc2080: humidity is less than low threshold and check the interrupt pin.\n");
411 }
412
413 /* delay 1000ms */
415 }
416
417 /* finish interrupt test and exit */
418 hdc2080_interface_debug_print("hdc2080: finish interrupt test.\n");
419 (void)hdc2080_deinit(&gs_handle);
420
421 return 0;
422}
driver hdc2080 interrupt test header file
uint8_t hdc2080_init(hdc2080_handle_t *handle)
initialize the chip
uint8_t hdc2080_set_temperature_offset_adjustment(hdc2080_handle_t *handle, int8_t offset)
set temperature offset adjustment
uint8_t hdc2080_set_temperature_low_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set temperature low threshold
uint8_t hdc2080_set_auto_measurement_mode(hdc2080_handle_t *handle, hdc2080_auto_measurement_mode_t mode)
set auto measurement mode
struct hdc2080_handle_s hdc2080_handle_t
hdc2080 handle structure definition
uint8_t hdc2080_set_humidity_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t resolution)
set humidity resolution
uint8_t hdc2080_read_temperature_humidity(hdc2080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read the temperature and humidity data
uint8_t hdc2080_deinit(hdc2080_handle_t *handle)
close the chip
uint8_t hdc2080_humidity_offset_convert_to_register(hdc2080_handle_t *handle, float percent, int8_t *reg)
convert the humidity offset to the register raw data
uint8_t hdc2080_set_temperature_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t resolution)
set temperature resolution
uint8_t hdc2080_temperature_offset_convert_to_register(hdc2080_handle_t *handle, float deg, int8_t *reg)
convert the temperature offset to the register raw data
uint8_t hdc2080_set_interrupt_pin(hdc2080_handle_t *handle, hdc2080_bool_t enable)
enable or disable interrupt pin
uint8_t hdc2080_set_humidity_low_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set humidity low threshold
uint8_t hdc2080_set_addr_pin(hdc2080_handle_t *handle, hdc2080_address_t addr_pin)
set the iic address pin
uint8_t hdc2080_set_mode(hdc2080_handle_t *handle, hdc2080_mode_t mode)
set the chip mode
uint8_t hdc2080_set_humidity_high_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set humidity high threshold
uint8_t hdc2080_set_interrupt_polarity(hdc2080_handle_t *handle, hdc2080_interrupt_polarity_t polarity)
set interrupt polarity
uint8_t hdc2080_set_interrupt_mode(hdc2080_handle_t *handle, hdc2080_interrupt_mode_t mode)
set interrupt mode
struct hdc2080_info_s hdc2080_info_t
hdc2080 information structure definition
uint8_t hdc2080_set_humidity_offset_adjustment(hdc2080_handle_t *handle, int8_t offset)
set humidity offset adjustment
uint8_t hdc2080_set_heater(hdc2080_handle_t *handle, hdc2080_bool_t enable)
enable or disable heater
uint8_t hdc2080_humidity_convert_to_register(hdc2080_handle_t *handle, float percent, uint8_t *reg)
convert the humidity to the register raw data
uint8_t hdc2080_info(hdc2080_info_t *info)
get chip's information
uint8_t hdc2080_set_interrupt(hdc2080_handle_t *handle, hdc2080_interrupt_t interrupt, hdc2080_bool_t enable)
enable or disable interrupt
uint8_t hdc2080_temperature_convert_to_register(hdc2080_handle_t *handle, float deg, uint8_t *reg)
convert the temperature to the register raw data
uint8_t hdc2080_set_temperature_high_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set temperature high threshold
uint8_t hdc2080_read_poll(hdc2080_handle_t *handle)
read poll
hdc2080_address_t
hdc2080 address enumeration definition
@ HDC2080_BOOL_TRUE
@ HDC2080_BOOL_FALSE
@ HDC2080_RESOLUTION_14_BIT
@ HDC2080_AUTO_MEASUREMENT_MODE_DISABLED
@ HDC2080_INTERRUPT_POLARITY_LOW
@ HDC2080_INTERRUPT_MODE_COMPARATOR
@ HDC2080_INTERRUPT_DRDY
@ HDC2080_INTERRUPT_HUMIDITY_HIGH_THRESHOLD
@ HDC2080_INTERRUPT_HUMIDITY_LOW_THRESHOLD
@ HDC2080_INTERRUPT_TEMPERATURE_LOW_THRESHOLD
@ HDC2080_INTERRUPT_TEMPERATURE_HIGH_THRESHOLD
@ HDC2080_MODE_HUMIDITY_TEMPERATURE
uint8_t hdc2080_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void hdc2080_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc2080_interface_iic_init(void)
interface iic bus init
uint8_t hdc2080_interface_iic_deinit(void)
interface iic bus deinit
uint8_t hdc2080_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void hdc2080_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hdc2080_interrupt_test(hdc2080_address_t addr_pin, float high_deg, float low_deg, float high_percent, float low_percent, uint32_t times)
interrupt test
uint32_t driver_version
char manufacturer_name[32]