LibDriver SHT30
Loading...
Searching...
No Matches
driver_sht30_read_test.c
Go to the documentation of this file.
1
37
39
40static sht30_handle_t gs_handle;
41
51uint8_t sht30_read_test(sht30_address_t addr_pin, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 sht30_info_t info;
56
57 /* link functions */
66
67 /* sht30 info */
68 res = sht30_info(&info);
69 if (res != 0)
70 {
71 sht30_interface_debug_print("sht30: get info failed.\n");
72
73 return 1;
74 }
75 else
76 {
77 /* print chip information */
78 sht30_interface_debug_print("sht30: chip is %s.\n", info.chip_name);
79 sht30_interface_debug_print("sht30: manufacturer is %s.\n", info.manufacturer_name);
80 sht30_interface_debug_print("sht30: interface is %s.\n", info.interface);
81 sht30_interface_debug_print("sht30: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
82 sht30_interface_debug_print("sht30: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
83 sht30_interface_debug_print("sht30: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
84 sht30_interface_debug_print("sht30: max current is %0.2fmA.\n", info.max_current_ma);
85 sht30_interface_debug_print("sht30: max temperature is %0.1fC.\n", info.temperature_max);
86 sht30_interface_debug_print("sht30: min temperature is %0.1fC.\n", info.temperature_min);
87 }
88
89 /* start read test */
90 sht30_interface_debug_print("sht30: start read test.\n");
91
92 /* set address pin */
93 res = sht30_set_addr_pin(&gs_handle, addr_pin);
94 if (res != 0)
95 {
96 sht30_interface_debug_print("sht30: set addr pin failed.\n");
97
98 return 1;
99 }
100
101 /* sht30 init */
102 res = sht30_init(&gs_handle);
103 if (res != 0)
104 {
105 sht30_interface_debug_print("sht30: init failed.\n");
106
107 return 1;
108 }
109
110 /* wait 10 ms */
112
113 /* set art */
114 res = sht30_set_art(&gs_handle);
115 if (res != 0)
116 {
117 sht30_interface_debug_print("sht30: set art failed.\n");
118 (void)sht30_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 /* wait 10 ms */
125
126 /* set default heater */
127 res = sht30_set_heater(&gs_handle, SHT30_BOOL_TRUE);
128 if (res != 0)
129 {
130 sht30_interface_debug_print("sht30: set heater failed.\n");
131 (void)sht30_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* wait 10 ms */
138 sht30_interface_debug_print("sht30: continuous read.\n");
139
140 /* set low repeatability */
141 sht30_interface_debug_print("sht30: set low repeatability.\n");
143 if (res != 0)
144 {
145 sht30_interface_debug_print("sht30: set repeatability failed.\n");
146 (void)sht30_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* set rate 0.5Hz */
152 sht30_interface_debug_print("sht30: set rate 0.5Hz.\n");
153
154 /* start continuous read */
156 if (res != 0)
157 {
158 sht30_interface_debug_print("sht30: start continuous failed.\n");
159 (void)sht30_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* wait 10 ms */
166 for (i = 0; i < times; i++)
167 {
168 uint16_t temperature_raw;
169 float temperature_s;
170 uint16_t humidity_raw;
171 float humidity_s;
172
173 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
174 if (res != 0)
175 {
176 sht30_interface_debug_print("sht30: continuous read failed.\n");
177 (void)sht30_deinit(&gs_handle);
178
179 return 1;
180 }
181 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
182 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
183
184 /* wait 2500 ms */
186 }
187
188 /* stop continuous read */
189 res = sht30_stop_continuous_read(&gs_handle);
190 if (res != 0)
191 {
192 sht30_interface_debug_print("sht30: stop continuous failed.\n");
193 (void)sht30_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 /* wait 10 ms */
200
201 /* set rate 1Hz */
202 sht30_interface_debug_print("sht30: set rate 1Hz.\n");
203
204 /* start continuous read */
206 if (res != 0)
207 {
208 sht30_interface_debug_print("sht30: start continuous failed.\n");
209 (void)sht30_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* wait 10 ms */
216 for (i = 0; i < times; i++)
217 {
218 uint16_t temperature_raw;
219 float temperature_s;
220 uint16_t humidity_raw;
221 float humidity_s;
222
223 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
224 if (res != 0)
225 {
226 sht30_interface_debug_print("sht30: continuous read failed.\n");
227 (void)sht30_deinit(&gs_handle);
228
229 return 1;
230 }
231 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
232 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
233
234 /* wait 1500 ms */
236 }
237
238 /* stop continuous read */
239 res = sht30_stop_continuous_read(&gs_handle);
240 if (res != 0)
241 {
242 sht30_interface_debug_print("sht30: stop continuous failed.\n");
243 (void)sht30_deinit(&gs_handle);
244
245 return 1;
246 }
247
248 /* wait 10 ms */
250
251 /* set rate 2Hz */
252 sht30_interface_debug_print("sht30: set rate 2Hz.\n");
253
254 /* start continuous read */
256 if (res != 0)
257 {
258 sht30_interface_debug_print("sht30: start continuous failed.\n");
259 (void)sht30_deinit(&gs_handle);
260
261 return 1;
262 }
263
264 /* wait 10 ms */
266 for (i = 0; i < times; i++)
267 {
268 uint16_t temperature_raw;
269 float temperature_s;
270 uint16_t humidity_raw;
271 float humidity_s;
272
273 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
274 if (res != 0)
275 {
276 sht30_interface_debug_print("sht30: continuous read failed.\n");
277 (void)sht30_deinit(&gs_handle);
278
279 return 1;
280 }
281 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
282 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
283
284 /* wait 1000 ms */
286 }
287
288 /* stop continuous read */
289 res = sht30_stop_continuous_read(&gs_handle);
290 if (res != 0)
291 {
292 sht30_interface_debug_print("sht30: stop continuous failed.\n");
293 (void)sht30_deinit(&gs_handle);
294
295 return 1;
296 }
297
298 /* wait 10 ms */
300
301 /* set rate 4Hz */
302 sht30_interface_debug_print("sht30: set rate 4Hz.\n");
303
304 /* start continuous read */
306 if (res != 0)
307 {
308 sht30_interface_debug_print("sht30: start continuous failed.\n");
309 (void)sht30_deinit(&gs_handle);
310
311 return 1;
312 }
313
314 /* wait 10 ms */
316 for (i = 0; i < times; i++)
317 {
318 uint16_t temperature_raw;
319 float temperature_s;
320 uint16_t humidity_raw;
321 float humidity_s;
322
323 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
324 if (res != 0)
325 {
326 sht30_interface_debug_print("sht30: continuous read failed.\n");
327 (void)sht30_deinit(&gs_handle);
328
329 return 1;
330 }
331 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
332 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
333
334 /* wait 500 ms */
336 }
337
338 /* stop continuous read */
339 res = sht30_stop_continuous_read(&gs_handle);
340 if (res != 0)
341 {
342 sht30_interface_debug_print("sht30: stop continuous failed.\n");
343 (void)sht30_deinit(&gs_handle);
344
345 return 1;
346 }
347
348 /* wait 10 ms */
350
351 /* set rate 10Hz */
352 sht30_interface_debug_print("sht30: set rate 10Hz.\n");
353
354 /* start continuous read */
356 if (res != 0)
357 {
358 sht30_interface_debug_print("sht30: start continuous failed.\n");
359 (void)sht30_deinit(&gs_handle);
360
361 return 1;
362 }
363
364 /* wait 10 ms */
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 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
374 if (res != 0)
375 {
376 sht30_interface_debug_print("sht30: continuous read failed.\n");
377 (void)sht30_deinit(&gs_handle);
378
379 return 1;
380 }
381 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
382 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
383
384 /* wait 500 ms */
386 }
387
388 /* stop continuous read */
389 res = sht30_stop_continuous_read(&gs_handle);
390 if (res != 0)
391 {
392 sht30_interface_debug_print("sht30: stop continuous failed.\n");
393 (void)sht30_deinit(&gs_handle);
394
395 return 1;
396 }
397
398 /* wait 10 ms */
400
401 /* set medium repeatability */
402 sht30_interface_debug_print("sht30: set medium repeatability.\n");
404 if (res != 0)
405 {
406 sht30_interface_debug_print("sht30: set repeatability failed.\n");
407 (void)sht30_deinit(&gs_handle);
408
409 return 1;
410 }
411
412 /* set rate 0.5Hz */
413 sht30_interface_debug_print("sht30: set rate 0.5Hz.\n");
414
415 /* start continuous read */
417 if (res != 0)
418 {
419 sht30_interface_debug_print("sht30: start continuous failed.\n");
420 (void)sht30_deinit(&gs_handle);
421
422 return 1;
423 }
424
425 /* wait 10 ms */
427 for (i = 0; i < times; i++)
428 {
429 uint16_t temperature_raw;
430 float temperature_s;
431 uint16_t humidity_raw;
432 float humidity_s;
433
434 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
435 if (res != 0)
436 {
437 sht30_interface_debug_print("sht30: continuous read failed.\n");
438 (void)sht30_deinit(&gs_handle);
439
440 return 1;
441 }
442 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
443 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
444
445 /* wait 2500 ms */
447 }
448
449 /* stop continuous read */
450 res = sht30_stop_continuous_read(&gs_handle);
451 if (res != 0)
452 {
453 sht30_interface_debug_print("sht30: stop continuous failed.\n");
454 (void)sht30_deinit(&gs_handle);
455
456 return 1;
457 }
458
459 /* wait 10 ms */
461
462 /* set rate 1Hz */
463 sht30_interface_debug_print("sht30: set rate 1Hz.\n");
464
465 /* start continuous read */
467 if (res != 0)
468 {
469 sht30_interface_debug_print("sht30: start continuous failed.\n");
470 (void)sht30_deinit(&gs_handle);
471
472 return 1;
473 }
474
475 /* wait 10 ms */
477 for (i = 0; i < times; i++)
478 {
479 uint16_t temperature_raw;
480 float temperature_s;
481 uint16_t humidity_raw;
482 float humidity_s;
483
484 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
485 if (res != 0)
486 {
487 sht30_interface_debug_print("sht30: continuous read failed.\n");
488 (void)sht30_deinit(&gs_handle);
489
490 return 1;
491 }
492 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
493 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
494
495 /* wait 1500 ms */
497 }
498
499 /* stop continuous read */
500 res = sht30_stop_continuous_read(&gs_handle);
501 if (res != 0)
502 {
503 sht30_interface_debug_print("sht30: stop continuous failed.\n");
504 (void)sht30_deinit(&gs_handle);
505
506 return 1;
507 }
508
509 /* wait 10 ms */
511
512 /* set rate 2Hz */
513 sht30_interface_debug_print("sht30: set rate 2Hz.\n");
514
515 /* start continuous read */
517 if (res != 0)
518 {
519 sht30_interface_debug_print("sht30: start continuous failed.\n");
520 (void)sht30_deinit(&gs_handle);
521
522 return 1;
523 }
524
525 /* wait 10 ms */
527 for (i = 0; i < times; i++)
528 {
529 uint16_t temperature_raw;
530 float temperature_s;
531 uint16_t humidity_raw;
532 float humidity_s;
533
534 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
535 if (res != 0)
536 {
537 sht30_interface_debug_print("sht30: continuous read failed.\n");
538 (void)sht30_deinit(&gs_handle);
539
540 return 1;
541 }
542 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
543 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
544
545 /* wait 1000 ms */
547 }
548
549 /* stop continuous read */
550 res = sht30_stop_continuous_read(&gs_handle);
551 if (res != 0)
552 {
553 sht30_interface_debug_print("sht30: stop continuous failed.\n");
554 (void)sht30_deinit(&gs_handle);
555
556 return 1;
557 }
558
559 /* wait 10 ms */
561
562 /* set rate 4Hz */
563 sht30_interface_debug_print("sht30: set rate 4Hz.\n");
564
565 /* start continuous read */
567 if (res != 0)
568 {
569 sht30_interface_debug_print("sht30: start continuous failed.\n");
570 (void)sht30_deinit(&gs_handle);
571
572 return 1;
573 }
574
575 /* wait 10 ms */
577 for (i = 0; i < times; i++)
578 {
579 uint16_t temperature_raw;
580 float temperature_s;
581 uint16_t humidity_raw;
582 float humidity_s;
583
584 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
585 if (res != 0)
586 {
587 sht30_interface_debug_print("sht30: continuous read failed.\n");
588 (void)sht30_deinit(&gs_handle);
589
590 return 1;
591 }
592 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
593 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
594
595 /* wait 500 ms */
597 }
598
599 /* stop continuous read */
600 res = sht30_stop_continuous_read(&gs_handle);
601 if (res != 0)
602 {
603 sht30_interface_debug_print("sht30: stop continuous failed.\n");
604 (void)sht30_deinit(&gs_handle);
605
606 return 1;
607 }
608
609 /* wait 10 ms */
611
612 /* set rate 10Hz */
613 sht30_interface_debug_print("sht30: set rate 10Hz.\n");
614
615 /* start continuous read */
617 if (res != 0)
618 {
619 sht30_interface_debug_print("sht30: start continuous failed.\n");
620 (void)sht30_deinit(&gs_handle);
621
622 return 1;
623 }
624
625 /* wait 10 ms */
627 for (i = 0; i < times; i++)
628 {
629 uint16_t temperature_raw;
630 float temperature_s;
631 uint16_t humidity_raw;
632 float humidity_s;
633
634 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
635 if (res != 0)
636 {
637 sht30_interface_debug_print("sht30: continuous read failed.\n");
638 (void)sht30_deinit(&gs_handle);
639
640 return 1;
641 }
642 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
643 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
644
645 /* wait 500 ms */
647 }
648
649 /* stop continuous read */
650 res = sht30_stop_continuous_read(&gs_handle);
651 if (res != 0)
652 {
653 sht30_interface_debug_print("sht30: stop continuous failed.\n");
654 (void)sht30_deinit(&gs_handle);
655
656 return 1;
657 }
658
659 /* wait 10 ms */
661
662 /* set high repeatability */
663 sht30_interface_debug_print("sht30: set high repeatability.\n");
665 if (res != 0)
666 {
667 sht30_interface_debug_print("sht30: set repeatability failed.\n");
668 (void)sht30_deinit(&gs_handle);
669
670 return 1;
671 }
672
673 /* set rate 0.5Hz */
674 sht30_interface_debug_print("sht30: set rate 0.5Hz.\n");
675
676 /* start continuous read */
678 if (res != 0)
679 {
680 sht30_interface_debug_print("sht30: start continuous failed.\n");
681 (void)sht30_deinit(&gs_handle);
682
683 return 1;
684 }
685
686 /* wait 10 ms */
688 for (i = 0; i < times; i++)
689 {
690 uint16_t temperature_raw;
691 float temperature_s;
692 uint16_t humidity_raw;
693 float humidity_s;
694
695 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
696 if (res != 0)
697 {
698 sht30_interface_debug_print("sht30: continuous read failed.\n");
699 (void)sht30_deinit(&gs_handle);
700
701 return 1;
702 }
703 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
704 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
705
706 /* wait 2500 ms */
708 }
709
710 /* stop continuous read */
711 res = sht30_stop_continuous_read(&gs_handle);
712 if (res != 0)
713 {
714 sht30_interface_debug_print("sht30: stop continuous failed.\n");
715 (void)sht30_deinit(&gs_handle);
716
717 return 1;
718 }
719
720 /* wait 10 ms */
722
723 /* set rate 1Hz */
724 sht30_interface_debug_print("sht30: set rate 1Hz.\n");
725
726 /* start continuous read */
728 if (res != 0)
729 {
730 sht30_interface_debug_print("sht30: start continuous failed.\n");
731 (void)sht30_deinit(&gs_handle);
732
733 return 1;
734 }
735
736 /* wait 10 ms */
738 for (i = 0; i < times; i++)
739 {
740 uint16_t temperature_raw;
741 float temperature_s;
742 uint16_t humidity_raw;
743 float humidity_s;
744
745 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
746 if (res != 0)
747 {
748 sht30_interface_debug_print("sht30: continuous read failed.\n");
749 (void)sht30_deinit(&gs_handle);
750
751 return 1;
752 }
753 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
754 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
755
756 /* wait 1500 ms */
758 }
759
760 /* stop continuous read */
761 res = sht30_stop_continuous_read(&gs_handle);
762 if (res != 0)
763 {
764 sht30_interface_debug_print("sht30: stop continuous failed.\n");
765 (void)sht30_deinit(&gs_handle);
766
767 return 1;
768 }
769
770 /* wait 10 ms */
772
773 /* set rate 2Hz */
774 sht30_interface_debug_print("sht30: set rate 2Hz.\n");
775
776 /* start continuous read */
778 if (res != 0)
779 {
780 sht30_interface_debug_print("sht30: start continuous failed.\n");
781 (void)sht30_deinit(&gs_handle);
782
783 return 1;
784 }
785
786 /* wait 10 ms */
788 for (i = 0; i < times; i++)
789 {
790 uint16_t temperature_raw;
791 float temperature_s;
792 uint16_t humidity_raw;
793 float humidity_s;
794
795 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
796 if (res != 0)
797 {
798 sht30_interface_debug_print("sht30: continuous read failed.\n");
799 (void)sht30_deinit(&gs_handle);
800
801 return 1;
802 }
803 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
804 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
805
806 /* wait 1000 ms */
808 }
809
810 /* stop continuous read */
811 res = sht30_stop_continuous_read(&gs_handle);
812 if (res != 0)
813 {
814 sht30_interface_debug_print("sht30: stop continuous failed.\n");
815 (void)sht30_deinit(&gs_handle);
816
817 return 1;
818 }
819
820 /* wait 10 ms */
822
823 /* set rate 4Hz */
824 sht30_interface_debug_print("sht30: set rate 4Hz.\n");
825
826 /* start continuous read */
828 if (res != 0)
829 {
830 sht30_interface_debug_print("sht30: start continuous failed.\n");
831 (void)sht30_deinit(&gs_handle);
832
833 return 1;
834 }
835
836 /* wait 10 ms */
838 for (i = 0; i < times; i++)
839 {
840 uint16_t temperature_raw;
841 float temperature_s;
842 uint16_t humidity_raw;
843 float humidity_s;
844
845 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
846 if (res != 0)
847 {
848 sht30_interface_debug_print("sht30: continuous read failed.\n");
849 (void)sht30_deinit(&gs_handle);
850
851 return 1;
852 }
853 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
854 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
855
856 /* wait 500 ms */
858 }
859
860 /* stop continuous read */
861 res = sht30_stop_continuous_read(&gs_handle);
862 if (res != 0)
863 {
864 sht30_interface_debug_print("sht30: stop continuous failed.\n");
865 (void)sht30_deinit(&gs_handle);
866
867 return 1;
868 }
869
870 /* wait 10 ms */
872
873 /* set rate 10Hz */
874 sht30_interface_debug_print("sht30: set rate 10Hz.\n");
875
876 /* start continuous read */
878 if (res != 0)
879 {
880 sht30_interface_debug_print("sht30: start continuous failed.\n");
881 (void)sht30_deinit(&gs_handle);
882
883 return 1;
884 }
885
886 /* wait 10 ms */
888 for (i = 0; i < times; i++)
889 {
890 uint16_t temperature_raw;
891 float temperature_s;
892 uint16_t humidity_raw;
893 float humidity_s;
894
895 res = sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
896 if (res != 0)
897 {
898 sht30_interface_debug_print("sht30: continuous read failed.\n");
899 (void)sht30_deinit(&gs_handle);
900
901 return 1;
902 }
903 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
904 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
905
906 /* wait 500 ms */
908 }
909
910 /* stop continuous read */
911 res = sht30_stop_continuous_read(&gs_handle);
912 if (res != 0)
913 {
914 sht30_interface_debug_print("sht30: stop continuous failed.\n");
915 (void)sht30_deinit(&gs_handle);
916
917 return 1;
918 }
919
920 /* wait 10 ms */
922
923 /* link iic read address16 with scl */
925 sht30_interface_debug_print("sht30: single read.\n");
926
927 /* set low repeatability */
928 sht30_interface_debug_print("sht30: set low repeatability.\n");
930 if (res != 0)
931 {
932 sht30_interface_debug_print("sht30: set repeatability failed.\n");
933 (void)sht30_deinit(&gs_handle);
934
935 return 1;
936 }
937 for (i = 0; i < times; i++)
938 {
939 uint16_t temperature_raw;
940 float temperature_s;
941 uint16_t humidity_raw;
942 float humidity_s;
943
944 res = sht30_single_read(&gs_handle, SHT30_BOOL_TRUE, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
945 if (res != 0)
946 {
947 sht30_interface_debug_print("sht30: single read failed.\n");
948 (void)sht30_deinit(&gs_handle);
949
950 return 1;
951 }
952 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
953 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
954
955 /* wait 1000 ms */
957 }
958
959 /* set medium repeatability */
960 sht30_interface_debug_print("sht30: set medium repeatability.\n");
962 if (res != 0)
963 {
964 sht30_interface_debug_print("sht30: set repeatability failed.\n");
965 (void)sht30_deinit(&gs_handle);
966
967 return 1;
968 }
969 for (i = 0; i < times; i++)
970 {
971 uint16_t temperature_raw;
972 float temperature_s;
973 uint16_t humidity_raw;
974 float humidity_s;
975
976 res = sht30_single_read(&gs_handle, SHT30_BOOL_TRUE, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
977 if (res != 0)
978 {
979 sht30_interface_debug_print("sht30: single read failed.\n");
980 (void)sht30_deinit(&gs_handle);
981
982 return 1;
983 }
984 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
985 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
986
987 /* wait 1000 ms */
989 }
990
991 /* set high repeatability */
992 sht30_interface_debug_print("sht30: set high repeatability.\n");
994 if (res != 0)
995 {
996 sht30_interface_debug_print("sht30: set repeatability failed.\n");
997 (void)sht30_deinit(&gs_handle);
998
999 return 1;
1000 }
1001 for (i = 0; i < times; i++)
1002 {
1003 uint16_t temperature_raw;
1004 float temperature_s;
1005 uint16_t humidity_raw;
1006 float humidity_s;
1007
1008 res = sht30_single_read(&gs_handle, SHT30_BOOL_TRUE, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
1009 if (res != 0)
1010 {
1011 sht30_interface_debug_print("sht30: single read failed.\n");
1012 (void)sht30_deinit(&gs_handle);
1013
1014 return 1;
1015 }
1016 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
1017 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
1018
1019 /* wait 1000 ms */
1021 }
1022
1023 /* disable clock stretching */
1024 sht30_interface_debug_print("sht30: disable clock stretching.\n");
1025 for (i = 0; i < times; i++)
1026 {
1027 uint16_t temperature_raw;
1028 float temperature_s;
1029 uint16_t humidity_raw;
1030 float humidity_s;
1031
1032 res = sht30_single_read(&gs_handle, SHT30_BOOL_FALSE, (uint16_t *)&temperature_raw, (float *)&temperature_s, (uint16_t *)&humidity_raw, (float *)&humidity_s);
1033 if (res != 0)
1034 {
1035 sht30_interface_debug_print("sht30: single read failed.\n");
1036 (void)sht30_deinit(&gs_handle);
1037
1038 return 1;
1039 }
1040 sht30_interface_debug_print("sht30: temperature is %0.2fC.\n", temperature_s);
1041 sht30_interface_debug_print("sht30: humidity is %0.2f%%.\n", humidity_s);
1042
1043 /* wait 1000 ms */
1045 }
1046
1047 /* finish read test */
1048 sht30_interface_debug_print("sht30: finish read test.\n");
1049 (void)sht30_deinit(&gs_handle);
1050
1051 return 0;
1052}
driver sht30 read test header file
uint8_t sht30_stop_continuous_read(sht30_handle_t *handle)
stop reading
uint8_t sht30_info(sht30_info_t *info)
get chip's information
uint8_t sht30_start_continuous_read(sht30_handle_t *handle, sht30_rate_t rate)
start reading
uint8_t sht30_set_repeatability(sht30_handle_t *handle, sht30_repeatability_t repeatability)
set the measurement repeatability
uint8_t sht30_single_read(sht30_handle_t *handle, sht30_bool_t clock_stretching_enable, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data once
uint8_t sht30_init(sht30_handle_t *handle)
initialize the chip
uint8_t sht30_set_art(sht30_handle_t *handle)
set the chip art
sht30_address_t
sht30 address enumeration definition
struct sht30_info_s sht30_info_t
sht30 information structure definition
uint8_t sht30_set_heater(sht30_handle_t *handle, sht30_bool_t enable)
enable or disable the chip heater
uint8_t sht30_set_addr_pin(sht30_handle_t *handle, sht30_address_t addr_pin)
set the iic address pin
uint8_t sht30_continuous_read(sht30_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data continuously
struct sht30_handle_s sht30_handle_t
sht30 handle structure definition
uint8_t sht30_deinit(sht30_handle_t *handle)
close the chip
@ SHT30_RATE_4HZ
@ SHT30_RATE_10HZ
@ SHT30_RATE_2HZ
@ SHT30_RATE_0P5HZ
@ SHT30_RATE_1HZ
@ SHT30_REPEATABILITY_MEDIUM
@ SHT30_REPEATABILITY_LOW
@ SHT30_REPEATABILITY_HIGH
@ SHT30_BOOL_TRUE
@ SHT30_BOOL_FALSE
uint8_t sht30_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
uint8_t sht30_interface_iic_init(void)
interface iic bus init
uint8_t sht30_interface_iic_deinit(void)
interface iic bus deinit
void sht30_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t sht30_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 sht30_interface_receive_callback(uint16_t type)
interface receive callback
void sht30_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t sht30_interface_iic_scl_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address
uint8_t sht30_read_test(sht30_address_t addr_pin, uint32_t times)
read 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]