LibDriver AD7705
Loading...
Searching...
No Matches
driver_ad7705_read_test.c
Go to the documentation of this file.
1
36
38
39static ad7705_handle_t gs_handle;
40
51uint8_t ad7705_read_test(ad7705_channel_t channel, float voltage, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 ad7705_info_t info;
56
57 /* link functions */
68
69 /* ad7705 info */
70 res = ad7705_info(&info);
71 if (res != 0)
72 {
73 ad7705_interface_debug_print("ad7705: get info failed.\n");
74
75 return 1;
76 }
77 else
78 {
79 /* print chip information */
80 ad7705_interface_debug_print("ad7705: chip is %s.\n", info.chip_name);
81 ad7705_interface_debug_print("ad7705: manufacturer is %s.\n", info.manufacturer_name);
82 ad7705_interface_debug_print("ad7705: interface is %s.\n", info.interface);
83 ad7705_interface_debug_print("ad7705: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
84 ad7705_interface_debug_print("ad7705: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
85 ad7705_interface_debug_print("ad7705: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
86 ad7705_interface_debug_print("ad7705: max current is %0.2fmA.\n", info.max_current_ma);
87 ad7705_interface_debug_print("ad7705: max temperature is %0.1fC.\n", info.temperature_max);
88 ad7705_interface_debug_print("ad7705: min temperature is %0.1fC.\n", info.temperature_min);
89 }
90
91 /* ad7705 init */
92 res = ad7705_init(&gs_handle);
93 if (res != 0)
94 {
95 ad7705_interface_debug_print("ad7705: init failed.\n");
96
97 return 1;
98 }
99
100 /* start read test */
101 ad7705_interface_debug_print("ad7705: start read test.\n");
102
103 /* power on */
104 res = ad7705_power_on(&gs_handle);
105 if (res != 0)
106 {
107 ad7705_interface_debug_print("ad7705: power on failed.\n");
108 (void)ad7705_deinit(&gs_handle);
109
110 return 1;
111 }
112
113 /* reference voltage */
114 res = ad7705_set_reference_voltage(&gs_handle, voltage);
115 if (res != 0)
116 {
117 ad7705_interface_debug_print("ad7705: reference voltage failed.\n");
118 (void)ad7705_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 /* set channel */
124 res = ad7705_set_channel(&gs_handle, channel);
125 if (res != 0)
126 {
127 ad7705_interface_debug_print("ad7705: set channel failed.\n");
128 (void)ad7705_deinit(&gs_handle);
129
130 return 1;
131 }
132
133 /* disable adc buffer */
134 res = ad7705_set_adc_buffer(&gs_handle, AD7705_BOOL_FALSE);
135 if (res != 0)
136 {
137 ad7705_interface_debug_print("ad7705: set adc buffer failed.\n");
138 (void)ad7705_deinit(&gs_handle);
139
140 return 1;
141 }
142
143 /* enable filter synchronize */
145 if (res != 0)
146 {
147 ad7705_interface_debug_print("ad7705: set filter synchronize failed.\n");
148 (void)ad7705_deinit(&gs_handle);
149
150 return 1;
151 }
152
153 /* enable master clock output */
155 if (res != 0)
156 {
157 ad7705_interface_debug_print("ad7705: set master clock output disable failed.\n");
158 (void)ad7705_deinit(&gs_handle);
159
160 return 1;
161 }
162
163 /* disable clock div2 */
164 res = ad7705_set_clock_div2(&gs_handle, AD7705_BOOL_FALSE);
165 if (res != 0)
166 {
167 ad7705_interface_debug_print("ad7705: set clock div2 failed.\n");
168 (void)ad7705_deinit(&gs_handle);
169
170 return 1;
171 }
172
173 /* set rate 50hz */
174 res = ad7705_set_rate(&gs_handle, AD7705_RATE_50HZ);
175 if (res != 0)
176 {
177 ad7705_interface_debug_print("ad7705: set rate failed.\n");
178 (void)ad7705_deinit(&gs_handle);
179
180 return 1;
181 }
182
183 /* set adc unipolar */
185 if (res != 0)
186 {
187 ad7705_interface_debug_print("ad7705: set adc polar failed.\n");
188 (void)ad7705_deinit(&gs_handle);
189
190 return 1;
191 }
192
193 /* set adc gain 1 */
194 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_1);
195 if (res != 0)
196 {
197 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
198 (void)ad7705_deinit(&gs_handle);
199
200 return 1;
201 }
202
203 /* run self calibration */
205 if (res != 0)
206 {
207 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
208 (void)ad7705_deinit(&gs_handle);
209
210 return 1;
211 }
212
213 /* wait for finishing */
214 res = ad7705_operate_sync(&gs_handle);
215 if (res != 0)
216 {
217 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
218 (void)ad7705_deinit(&gs_handle);
219
220 return 1;
221 }
222
223 /* output */
224 ad7705_interface_debug_print("ad7705: unipolar mode test.\n");
225
226 /* output */
227 ad7705_interface_debug_print("ad7705: set gain1.\n");
228
229 for (i = 0; i < times; i++)
230 {
231 uint16_t raw;
232 float volt;
233
234 /* read data */
235 res = ad7705_read(&gs_handle, &raw, &volt);
236 if (res != 0)
237 {
238 ad7705_interface_debug_print("ad7705: read failed.\n");
239 (void)ad7705_deinit(&gs_handle);
240
241 return 1;
242 }
243
244 /* output */
245 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
246
247 /* delay 1000ms */
249 }
250
251 /* set adc gain 2 */
252 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_2);
253 if (res != 0)
254 {
255 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
256 (void)ad7705_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* run self calibration */
263 if (res != 0)
264 {
265 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
266 (void)ad7705_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* wait for finishing */
272 res = ad7705_operate_sync(&gs_handle);
273 if (res != 0)
274 {
275 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
276 (void)ad7705_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* output */
282 ad7705_interface_debug_print("ad7705: set gain2.\n");
283
284 for (i = 0; i < times; i++)
285 {
286 uint16_t raw;
287 float volt;
288
289 /* read data */
290 res = ad7705_read(&gs_handle, &raw, &volt);
291 if (res != 0)
292 {
293 ad7705_interface_debug_print("ad7705: read failed.\n");
294 (void)ad7705_deinit(&gs_handle);
295
296 return 1;
297 }
298
299 /* output */
300 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
301
302 /* delay 1000ms */
304 }
305
306 /* set adc gain 4 */
307 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_4);
308 if (res != 0)
309 {
310 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
311 (void)ad7705_deinit(&gs_handle);
312
313 return 1;
314 }
315
316 /* run self calibration */
318 if (res != 0)
319 {
320 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
321 (void)ad7705_deinit(&gs_handle);
322
323 return 1;
324 }
325
326 /* wait for finishing */
327 res = ad7705_operate_sync(&gs_handle);
328 if (res != 0)
329 {
330 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
331 (void)ad7705_deinit(&gs_handle);
332
333 return 1;
334 }
335
336 /* output */
337 ad7705_interface_debug_print("ad7705: set gain4.\n");
338
339 for (i = 0; i < times; i++)
340 {
341 uint16_t raw;
342 float volt;
343
344 /* read data */
345 res = ad7705_read(&gs_handle, &raw, &volt);
346 if (res != 0)
347 {
348 ad7705_interface_debug_print("ad7705: read failed.\n");
349 (void)ad7705_deinit(&gs_handle);
350
351 return 1;
352 }
353
354 /* output */
355 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
356
357 /* delay 1000ms */
359 }
360
361 /* set adc gain 8 */
362 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_8);
363 if (res != 0)
364 {
365 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
366 (void)ad7705_deinit(&gs_handle);
367
368 return 1;
369 }
370
371 /* run self calibration */
373 if (res != 0)
374 {
375 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
376 (void)ad7705_deinit(&gs_handle);
377
378 return 1;
379 }
380
381 /* wait for finishing */
382 res = ad7705_operate_sync(&gs_handle);
383 if (res != 0)
384 {
385 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
386 (void)ad7705_deinit(&gs_handle);
387
388 return 1;
389 }
390
391 /* output */
392 ad7705_interface_debug_print("ad7705: set gain8.\n");
393
394 for (i = 0; i < times; i++)
395 {
396 uint16_t raw;
397 float volt;
398
399 /* read data */
400 res = ad7705_read(&gs_handle, &raw, &volt);
401 if (res != 0)
402 {
403 ad7705_interface_debug_print("ad7705: read failed.\n");
404 (void)ad7705_deinit(&gs_handle);
405
406 return 1;
407 }
408
409 /* output */
410 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
411
412 /* delay 1000ms */
414 }
415
416 /* set adc gain 16 */
417 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_16);
418 if (res != 0)
419 {
420 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
421 (void)ad7705_deinit(&gs_handle);
422
423 return 1;
424 }
425
426 /* run self calibration */
428 if (res != 0)
429 {
430 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
431 (void)ad7705_deinit(&gs_handle);
432
433 return 1;
434 }
435
436 /* wait for finishing */
437 res = ad7705_operate_sync(&gs_handle);
438 if (res != 0)
439 {
440 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
441 (void)ad7705_deinit(&gs_handle);
442
443 return 1;
444 }
445
446 /* output */
447 ad7705_interface_debug_print("ad7705: set gain16.\n");
448
449 for (i = 0; i < times; i++)
450 {
451 uint16_t raw;
452 float volt;
453
454 /* read data */
455 res = ad7705_read(&gs_handle, &raw, &volt);
456 if (res != 0)
457 {
458 ad7705_interface_debug_print("ad7705: read failed.\n");
459 (void)ad7705_deinit(&gs_handle);
460
461 return 1;
462 }
463
464 /* output */
465 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
466
467 /* delay 1000ms */
469 }
470
471 /* set adc gain 32 */
472 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_32);
473 if (res != 0)
474 {
475 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
476 (void)ad7705_deinit(&gs_handle);
477
478 return 1;
479 }
480
481 /* run self calibration */
483 if (res != 0)
484 {
485 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
486 (void)ad7705_deinit(&gs_handle);
487
488 return 1;
489 }
490
491 /* wait for finishing */
492 res = ad7705_operate_sync(&gs_handle);
493 if (res != 0)
494 {
495 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
496 (void)ad7705_deinit(&gs_handle);
497
498 return 1;
499 }
500
501 /* output */
502 ad7705_interface_debug_print("ad7705: set gain32.\n");
503
504 for (i = 0; i < times; i++)
505 {
506 uint16_t raw;
507 float volt;
508
509 /* read data */
510 res = ad7705_read(&gs_handle, &raw, &volt);
511 if (res != 0)
512 {
513 ad7705_interface_debug_print("ad7705: read failed.\n");
514 (void)ad7705_deinit(&gs_handle);
515
516 return 1;
517 }
518
519 /* output */
520 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
521
522 /* delay 1000ms */
524 }
525
526 /* set adc gain 64 */
527 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_64);
528 if (res != 0)
529 {
530 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
531 (void)ad7705_deinit(&gs_handle);
532
533 return 1;
534 }
535
536 /* run self calibration */
538 if (res != 0)
539 {
540 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
541 (void)ad7705_deinit(&gs_handle);
542
543 return 1;
544 }
545
546 /* wait for finishing */
547 res = ad7705_operate_sync(&gs_handle);
548 if (res != 0)
549 {
550 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
551 (void)ad7705_deinit(&gs_handle);
552
553 return 1;
554 }
555
556 /* output */
557 ad7705_interface_debug_print("ad7705: set gain64.\n");
558
559 for (i = 0; i < times; i++)
560 {
561 uint16_t raw;
562 float volt;
563
564 /* read data */
565 res = ad7705_read(&gs_handle, &raw, &volt);
566 if (res != 0)
567 {
568 ad7705_interface_debug_print("ad7705: read failed.\n");
569 (void)ad7705_deinit(&gs_handle);
570
571 return 1;
572 }
573
574 /* output */
575 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
576
577 /* delay 1000ms */
579 }
580
581 /* set adc gain 128 */
582 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_128);
583 if (res != 0)
584 {
585 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
586 (void)ad7705_deinit(&gs_handle);
587
588 return 1;
589 }
590
591 /* run self calibration */
593 if (res != 0)
594 {
595 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
596 (void)ad7705_deinit(&gs_handle);
597
598 return 1;
599 }
600
601 /* wait for finishing */
602 res = ad7705_operate_sync(&gs_handle);
603 if (res != 0)
604 {
605 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
606 (void)ad7705_deinit(&gs_handle);
607
608 return 1;
609 }
610
611 /* output */
612 ad7705_interface_debug_print("ad7705: set gain128.\n");
613
614 for (i = 0; i < times; i++)
615 {
616 uint16_t raw;
617 float volt;
618
619 /* read data */
620 res = ad7705_read(&gs_handle, &raw, &volt);
621 if (res != 0)
622 {
623 ad7705_interface_debug_print("ad7705: read failed.\n");
624 (void)ad7705_deinit(&gs_handle);
625
626 return 1;
627 }
628
629 /* output */
630 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
631
632 /* delay 1000ms */
634 }
635
636 /* set adc gain 1 */
637 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_1);
638 if (res != 0)
639 {
640 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
641 (void)ad7705_deinit(&gs_handle);
642
643 return 1;
644 }
645
646 /* set adc bipolar */
648 if (res != 0)
649 {
650 ad7705_interface_debug_print("ad7705: set adc polar failed.\n");
651 (void)ad7705_deinit(&gs_handle);
652
653 return 1;
654 }
655
656 /* run self calibration */
658 if (res != 0)
659 {
660 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
661 (void)ad7705_deinit(&gs_handle);
662
663 return 1;
664 }
665
666 /* wait for finishing */
667 res = ad7705_operate_sync(&gs_handle);
668 if (res != 0)
669 {
670 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
671 (void)ad7705_deinit(&gs_handle);
672
673 return 1;
674 }
675
676 /* output */
677 ad7705_interface_debug_print("ad7705: bipolar mode test.\n");
678
679 /* output */
680 ad7705_interface_debug_print("ad7705: set gain1.\n");
681
682 for (i = 0; i < times; i++)
683 {
684 uint16_t raw;
685 float volt;
686
687 /* read data */
688 res = ad7705_read(&gs_handle, &raw, &volt);
689 if (res != 0)
690 {
691 ad7705_interface_debug_print("ad7705: read failed.\n");
692 (void)ad7705_deinit(&gs_handle);
693
694 return 1;
695 }
696
697 /* output */
698 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
699
700 /* delay 1000ms */
702 }
703
704 /* set adc gain 2 */
705 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_2);
706 if (res != 0)
707 {
708 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
709 (void)ad7705_deinit(&gs_handle);
710
711 return 1;
712 }
713
714 /* run self calibration */
716 if (res != 0)
717 {
718 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
719 (void)ad7705_deinit(&gs_handle);
720
721 return 1;
722 }
723
724 /* wait for finishing */
725 res = ad7705_operate_sync(&gs_handle);
726 if (res != 0)
727 {
728 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
729 (void)ad7705_deinit(&gs_handle);
730
731 return 1;
732 }
733
734 /* output */
735 ad7705_interface_debug_print("ad7705: set gain2.\n");
736
737 for (i = 0; i < times; i++)
738 {
739 uint16_t raw;
740 float volt;
741
742 /* read data */
743 res = ad7705_read(&gs_handle, &raw, &volt);
744 if (res != 0)
745 {
746 ad7705_interface_debug_print("ad7705: read failed.\n");
747 (void)ad7705_deinit(&gs_handle);
748
749 return 1;
750 }
751
752 /* output */
753 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
754
755 /* delay 1000ms */
757 }
758
759 /* set adc gain 4 */
760 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_4);
761 if (res != 0)
762 {
763 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
764 (void)ad7705_deinit(&gs_handle);
765
766 return 1;
767 }
768
769 /* run self calibration */
771 if (res != 0)
772 {
773 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
774 (void)ad7705_deinit(&gs_handle);
775
776 return 1;
777 }
778
779 /* wait for finishing */
780 res = ad7705_operate_sync(&gs_handle);
781 if (res != 0)
782 {
783 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
784 (void)ad7705_deinit(&gs_handle);
785
786 return 1;
787 }
788
789 /* output */
790 ad7705_interface_debug_print("ad7705: set gain4.\n");
791
792 for (i = 0; i < times; i++)
793 {
794 uint16_t raw;
795 float volt;
796
797 /* read data */
798 res = ad7705_read(&gs_handle, &raw, &volt);
799 if (res != 0)
800 {
801 ad7705_interface_debug_print("ad7705: read failed.\n");
802 (void)ad7705_deinit(&gs_handle);
803
804 return 1;
805 }
806
807 /* output */
808 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
809
810 /* delay 1000ms */
812 }
813
814 /* set adc gain 8 */
815 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_8);
816 if (res != 0)
817 {
818 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
819 (void)ad7705_deinit(&gs_handle);
820
821 return 1;
822 }
823
824 /* run self calibration */
826 if (res != 0)
827 {
828 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
829 (void)ad7705_deinit(&gs_handle);
830
831 return 1;
832 }
833
834 /* wait for finishing */
835 res = ad7705_operate_sync(&gs_handle);
836 if (res != 0)
837 {
838 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
839 (void)ad7705_deinit(&gs_handle);
840
841 return 1;
842 }
843
844 /* output */
845 ad7705_interface_debug_print("ad7705: set gain8.\n");
846
847 for (i = 0; i < times; i++)
848 {
849 uint16_t raw;
850 float volt;
851
852 /* read data */
853 res = ad7705_read(&gs_handle, &raw, &volt);
854 if (res != 0)
855 {
856 ad7705_interface_debug_print("ad7705: read failed.\n");
857 (void)ad7705_deinit(&gs_handle);
858
859 return 1;
860 }
861
862 /* output */
863 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
864
865 /* delay 1000ms */
867 }
868
869 /* set adc gain 16 */
870 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_16);
871 if (res != 0)
872 {
873 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
874 (void)ad7705_deinit(&gs_handle);
875
876 return 1;
877 }
878
879 /* run self calibration */
881 if (res != 0)
882 {
883 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
884 (void)ad7705_deinit(&gs_handle);
885
886 return 1;
887 }
888
889 /* wait for finishing */
890 res = ad7705_operate_sync(&gs_handle);
891 if (res != 0)
892 {
893 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
894 (void)ad7705_deinit(&gs_handle);
895
896 return 1;
897 }
898
899 /* output */
900 ad7705_interface_debug_print("ad7705: set gain16.\n");
901
902 for (i = 0; i < times; i++)
903 {
904 uint16_t raw;
905 float volt;
906
907 /* read data */
908 res = ad7705_read(&gs_handle, &raw, &volt);
909 if (res != 0)
910 {
911 ad7705_interface_debug_print("ad7705: read failed.\n");
912 (void)ad7705_deinit(&gs_handle);
913
914 return 1;
915 }
916
917 /* output */
918 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
919
920 /* delay 1000ms */
922 }
923
924 /* set adc gain 32 */
925 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_32);
926 if (res != 0)
927 {
928 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
929 (void)ad7705_deinit(&gs_handle);
930
931 return 1;
932 }
933
934 /* run self calibration */
936 if (res != 0)
937 {
938 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
939 (void)ad7705_deinit(&gs_handle);
940
941 return 1;
942 }
943
944 /* wait for finishing */
945 res = ad7705_operate_sync(&gs_handle);
946 if (res != 0)
947 {
948 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
949 (void)ad7705_deinit(&gs_handle);
950
951 return 1;
952 }
953
954 /* output */
955 ad7705_interface_debug_print("ad7705: set gain32.\n");
956
957 for (i = 0; i < times; i++)
958 {
959 uint16_t raw;
960 float volt;
961
962 /* read data */
963 res = ad7705_read(&gs_handle, &raw, &volt);
964 if (res != 0)
965 {
966 ad7705_interface_debug_print("ad7705: read failed.\n");
967 (void)ad7705_deinit(&gs_handle);
968
969 return 1;
970 }
971
972 /* output */
973 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
974
975 /* delay 1000ms */
977 }
978
979 /* set adc gain 64 */
980 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_64);
981 if (res != 0)
982 {
983 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
984 (void)ad7705_deinit(&gs_handle);
985
986 return 1;
987 }
988
989 /* run self calibration */
991 if (res != 0)
992 {
993 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
994 (void)ad7705_deinit(&gs_handle);
995
996 return 1;
997 }
998
999 /* wait for finishing */
1000 res = ad7705_operate_sync(&gs_handle);
1001 if (res != 0)
1002 {
1003 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
1004 (void)ad7705_deinit(&gs_handle);
1005
1006 return 1;
1007 }
1008
1009 /* output */
1010 ad7705_interface_debug_print("ad7705: set gain64.\n");
1011
1012 for (i = 0; i < times; i++)
1013 {
1014 uint16_t raw;
1015 float volt;
1016
1017 /* read data */
1018 res = ad7705_read(&gs_handle, &raw, &volt);
1019 if (res != 0)
1020 {
1021 ad7705_interface_debug_print("ad7705: read failed.\n");
1022 (void)ad7705_deinit(&gs_handle);
1023
1024 return 1;
1025 }
1026
1027 /* output */
1028 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
1029
1030 /* delay 1000ms */
1032 }
1033
1034 /* set adc gain 128 */
1035 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_128);
1036 if (res != 0)
1037 {
1038 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
1039 (void)ad7705_deinit(&gs_handle);
1040
1041 return 1;
1042 }
1043
1044 /* run self calibration */
1046 if (res != 0)
1047 {
1048 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
1049 (void)ad7705_deinit(&gs_handle);
1050
1051 return 1;
1052 }
1053
1054 /* wait for finishing */
1055 res = ad7705_operate_sync(&gs_handle);
1056 if (res != 0)
1057 {
1058 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
1059 (void)ad7705_deinit(&gs_handle);
1060
1061 return 1;
1062 }
1063
1064 /* output */
1065 ad7705_interface_debug_print("ad7705: set gain128.\n");
1066
1067 for (i = 0; i < times; i++)
1068 {
1069 uint16_t raw;
1070 float volt;
1071
1072 /* read data */
1073 res = ad7705_read(&gs_handle, &raw, &volt);
1074 if (res != 0)
1075 {
1076 ad7705_interface_debug_print("ad7705: read failed.\n");
1077 (void)ad7705_deinit(&gs_handle);
1078
1079 return 1;
1080 }
1081
1082 /* output */
1083 ad7705_interface_debug_print("ad7705: adc is %0.5fV.\n", volt);
1084
1085 /* delay 1000ms */
1087 }
1088
1089 /* finish read test */
1090 ad7705_interface_debug_print("ad7705: finish read test.\n");
1091 (void)ad7705_deinit(&gs_handle);
1092
1093 return 0;
1094}
driver ad7705 read test header file
uint8_t ad7705_set_master_clock_output_disable(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable master clock output disable
ad7705_channel_t
ad7705 channel enumeration definition
struct ad7705_handle_s ad7705_handle_t
ad7705 handle structure definition
uint8_t ad7705_init(ad7705_handle_t *handle)
initialize the chip
uint8_t ad7705_set_adc_buffer(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable adc buffer
uint8_t ad7705_set_reference_voltage(ad7705_handle_t *handle, float voltage)
set reference voltage
uint8_t ad7705_operate_sync(ad7705_handle_t *handle)
operate sync
uint8_t ad7705_deinit(ad7705_handle_t *handle)
close the chip
uint8_t ad7705_set_adc_gain(ad7705_handle_t *handle, ad7705_adc_gain_t gain)
set adc gain
uint8_t ad7705_set_rate(ad7705_handle_t *handle, ad7705_rate_t rate)
set rate
uint8_t ad7705_read(ad7705_handle_t *handle, uint16_t *raw, float *volt)
read adc
uint8_t ad7705_set_clock_div2(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable clock div2
uint8_t ad7705_set_adc_mode(ad7705_handle_t *handle, ad7705_adc_mode_t mode)
set adc mode
uint8_t ad7705_power_on(ad7705_handle_t *handle)
power on
struct ad7705_info_s ad7705_info_t
ad7705 information structure definition
uint8_t ad7705_set_channel(ad7705_handle_t *handle, ad7705_channel_t channel)
set channel
uint8_t ad7705_info(ad7705_info_t *info)
get chip's information
uint8_t ad7705_set_adc_polar(ad7705_handle_t *handle, ad7705_adc_polar_t polar)
set adc polar
uint8_t ad7705_set_filter_synchronize(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable filter synchronize
@ AD7705_BOOL_FALSE
@ AD7705_BOOL_TRUE
@ AD7705_ADC_MODE_SELF_CALIBRATION
@ AD7705_ADC_POLAR_UNIPOLAR
@ AD7705_ADC_POLAR_BIPOLAR
@ AD7705_RATE_50HZ
@ AD7705_ADC_GAIN_128
@ AD7705_ADC_GAIN_4
@ AD7705_ADC_GAIN_1
@ AD7705_ADC_GAIN_2
@ AD7705_ADC_GAIN_8
@ AD7705_ADC_GAIN_32
@ AD7705_ADC_GAIN_16
@ AD7705_ADC_GAIN_64
uint8_t ad7705_interface_spi_write(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t ad7705_interface_spi_read(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t ad7705_interface_gpio_reset_deinit(void)
interface gpio reset deinit
void ad7705_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ad7705_interface_gpio_reset_write(uint8_t level)
interface gpio reset write
uint8_t ad7705_interface_spi_init(void)
interface spi bus init
uint8_t ad7705_interface_gpio_reset_init(void)
interface gpio reset init
uint8_t ad7705_interface_spi_deinit(void)
interface spi bus deinit
void ad7705_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ad7705_read_test(ad7705_channel_t channel, float voltage, uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]