LibDriver AD7705
Loading...
Searching...
No Matches
driver_ad7705_register_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static ad7705_handle_t gs_handle;
41
50{
51 uint8_t res;
52 uint8_t data;
53 uint8_t data_check;
54 uint16_t adc_data;
55 uint32_t calibration;
56 uint32_t calibration_check;
57 float voltage;
58 float voltage_check;
59 ad7705_info_t info;
60 ad7705_bool_t enable;
61 ad7705_channel_t channel;
65 ad7705_rate_t rate;
66
67 /* link functions */
78
79 /* get information */
80 res = ad7705_info(&info);
81 if (res != 0)
82 {
83 ad7705_interface_debug_print("ad7705: get info failed.\n");
84
85 return 1;
86 }
87 else
88 {
89 /* print chip info */
90 ad7705_interface_debug_print("ad7705: chip is %s.\n", info.chip_name);
91 ad7705_interface_debug_print("ad7705: manufacturer is %s.\n", info.manufacturer_name);
92 ad7705_interface_debug_print("ad7705: interface is %s.\n", info.interface);
93 ad7705_interface_debug_print("ad7705: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
94 ad7705_interface_debug_print("ad7705: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
95 ad7705_interface_debug_print("ad7705: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
96 ad7705_interface_debug_print("ad7705: max current is %0.2fmA.\n", info.max_current_ma);
97 ad7705_interface_debug_print("ad7705: max temperature is %0.1fC.\n", info.temperature_max);
98 ad7705_interface_debug_print("ad7705: min temperature is %0.1fC.\n", info.temperature_min);
99 }
100
101 /* start register test */
102 ad7705_interface_debug_print("ad7705: start register test.\n");
103
104 /* ad7705 init */
105 res = ad7705_init(&gs_handle);
106 if (res != 0)
107 {
108 ad7705_interface_debug_print("ad7705: init failed.\n");
109
110 return 1;
111 }
112
113 /* ad7705_set_reference_voltage/ad7705_get_reference_voltage test */
114 ad7705_interface_debug_print("ad7705: ad7705_set_reference_voltage/ad7705_get_reference_voltage test.\n");
115
116 voltage = (float)(rand() % 1000) / 100.0f;
117 res = ad7705_set_reference_voltage(&gs_handle, voltage);
118 if (res != 0)
119 {
120 ad7705_interface_debug_print("ad7705: set reference voltage failed.\n");
121 (void)ad7705_deinit(&gs_handle);
122
123 return 1;
124 }
125 ad7705_interface_debug_print("ad7705: set reference voltage %0.2f.\n", voltage);
126 res = ad7705_get_reference_voltage(&gs_handle, &voltage_check);
127 if (res != 0)
128 {
129 ad7705_interface_debug_print("ad7705: get reference voltage failed.\n");
130 (void)ad7705_deinit(&gs_handle);
131
132 return 1;
133 }
134 ad7705_interface_debug_print("ad7705: check reference voltage %0.2f.\n", voltage_check);
135
136 /* ad7705_set_channel/ad7705_get_channel test */
137 ad7705_interface_debug_print("ad7705: ad7705_set_channel/ad7705_get_channel test.\n");
138
139 /* set channel ain1 positive - ain1 negative */
141 if (res != 0)
142 {
143 ad7705_interface_debug_print("ad7705: set channel failed.\n");
144 (void)ad7705_deinit(&gs_handle);
145
146 return 1;
147 }
148 ad7705_interface_debug_print("ad7705: set channel ain1 positive - ain1 negative.\n");
149 res = ad7705_get_channel(&gs_handle, &channel);
150 if (res != 0)
151 {
152 ad7705_interface_debug_print("ad7705: get channel failed.\n");
153 (void)ad7705_deinit(&gs_handle);
154
155 return 1;
156 }
157 ad7705_interface_debug_print("ad7705: check interface %s.\n", (channel == AD7705_CHANNEL_AIN1_POSITIVE_AIN1_NEGATIVE) ? "ok" : "error");
158
159 /* set channel ain2 positive - ain2 negative */
161 if (res != 0)
162 {
163 ad7705_interface_debug_print("ad7705: set channel failed.\n");
164 (void)ad7705_deinit(&gs_handle);
165
166 return 1;
167 }
168 ad7705_interface_debug_print("ad7705: set channel ain2 positive - ain2 negative.\n");
169 res = ad7705_get_channel(&gs_handle, &channel);
170 if (res != 0)
171 {
172 ad7705_interface_debug_print("ad7705: get channel failed.\n");
173 (void)ad7705_deinit(&gs_handle);
174
175 return 1;
176 }
177 ad7705_interface_debug_print("ad7705: check interface %s.\n", (channel == AD7705_CHANNEL_AIN2_POSITIVE_AIN2_NEGATIVE) ? "ok" : "error");
178
179 /* set channel ain1 negative - ain1 negative */
181 if (res != 0)
182 {
183 ad7705_interface_debug_print("ad7705: set channel failed.\n");
184 (void)ad7705_deinit(&gs_handle);
185
186 return 1;
187 }
188 ad7705_interface_debug_print("ad7705: set channel ain1 negative - ain1 negative.\n");
189 res = ad7705_get_channel(&gs_handle, &channel);
190 if (res != 0)
191 {
192 ad7705_interface_debug_print("ad7705: get channel failed.\n");
193 (void)ad7705_deinit(&gs_handle);
194
195 return 1;
196 }
197 ad7705_interface_debug_print("ad7705: check interface %s.\n", (channel == AD7705_CHANNEL_AIN1_NEGATIVE_AIN1_NEGATIVE) ? "ok" : "error");
198
199 /* set channel ain1 negative - ain2 negative */
201 if (res != 0)
202 {
203 ad7705_interface_debug_print("ad7705: set channel failed.\n");
204 (void)ad7705_deinit(&gs_handle);
205
206 return 1;
207 }
208 ad7705_interface_debug_print("ad7705: set channel ain1 negative - ain2 negative.\n");
209 res = ad7705_get_channel(&gs_handle, &channel);
210 if (res != 0)
211 {
212 ad7705_interface_debug_print("ad7705: get channel failed.\n");
213 (void)ad7705_deinit(&gs_handle);
214
215 return 1;
216 }
217 ad7705_interface_debug_print("ad7705: check interface %s.\n", (channel == AD7705_CHANNEL_AIN1_NEGATIVE_AIN2_NEGATIVE) ? "ok" : "error");
218
219 /* ad7705_set_adc_mode/ad7705_get_adc_mode test */
220 ad7705_interface_debug_print("ad7705: ad7705_set_adc_mode/ad7705_get_adc_mode test.\n");
221
222 /* set adc normal mode */
224 if (res != 0)
225 {
226 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
227 (void)ad7705_deinit(&gs_handle);
228
229 return 1;
230 }
232 ad7705_interface_debug_print("ad7705: set adc normal mode.\n");
233 res = ad7705_get_adc_mode(&gs_handle, &mode);
234 if (res != 0)
235 {
236 ad7705_interface_debug_print("ad7705: get adc mode failed.\n");
237 (void)ad7705_deinit(&gs_handle);
238
239 return 1;
240 }
241 ad7705_interface_debug_print("ad7705: check adc mode %s.\n", (mode == AD7705_ADC_MODE_NORMAL) ? "ok" : "error");
242
243 /* set self calibration mode */
245 if (res != 0)
246 {
247 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
248 (void)ad7705_deinit(&gs_handle);
249
250 return 1;
251 }
252 ad7705_interface_debug_print("ad7705: set self calibration mode.\n");
253 res = ad7705_operate_sync(&gs_handle);
254 if (res != 0)
255 {
256 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
257 (void)ad7705_deinit(&gs_handle);
258
259 return 1;
260 }
261 res = ad7705_get_adc_mode(&gs_handle, &mode);
262 if (res != 0)
263 {
264 ad7705_interface_debug_print("ad7705: get adc mode failed.\n");
265 (void)ad7705_deinit(&gs_handle);
266
267 return 1;
268 }
269 ad7705_interface_debug_print("ad7705: check adc mode %s.\n", (res == 0) ? "ok" : "error");
270
271 /* set zero scale system calibration mode */
273 if (res != 0)
274 {
275 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
276 (void)ad7705_deinit(&gs_handle);
277
278 return 1;
279 }
280 ad7705_interface_debug_print("ad7705: set zero scale system calibration mode.\n");
281 res = ad7705_operate_sync(&gs_handle);
282 if (res != 0)
283 {
284 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
285 (void)ad7705_deinit(&gs_handle);
286
287 return 1;
288 }
289 res = ad7705_get_adc_mode(&gs_handle, &mode);
290 if (res != 0)
291 {
292 ad7705_interface_debug_print("ad7705: get adc mode failed.\n");
293 (void)ad7705_deinit(&gs_handle);
294
295 return 1;
296 }
297 ad7705_interface_debug_print("ad7705: check adc mode %s.\n", (res == 0) ? "ok" : "error");
298
299 /* set full scale system calibration mode */
301 if (res != 0)
302 {
303 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
304 (void)ad7705_deinit(&gs_handle);
305
306 return 1;
307 }
308 ad7705_interface_debug_print("ad7705: set full scale system calibration mode.\n");
309 res = ad7705_operate_sync(&gs_handle);
310 if (res != 0)
311 {
312 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
313 (void)ad7705_deinit(&gs_handle);
314
315 return 1;
316 }
317 res = ad7705_get_adc_mode(&gs_handle, &mode);
318 if (res != 0)
319 {
320 ad7705_interface_debug_print("ad7705: get adc mode failed.\n");
321 (void)ad7705_deinit(&gs_handle);
322
323 return 1;
324 }
325 ad7705_interface_debug_print("ad7705: check adc mode %s.\n", (res == 0) ? "ok" : "error");
327
328 /* ad7705_set_adc_gain/ad7705_get_adc_gain test */
329 ad7705_interface_debug_print("ad7705: ad7705_set_adc_gain/ad7705_get_adc_gain test.\n");
330
331 /* set adc gain1 */
332 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_1);
333 if (res != 0)
334 {
335 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
336 (void)ad7705_deinit(&gs_handle);
337
338 return 1;
339 }
340 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_1);
341 if (res != 0)
342 {
343 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
344 (void)ad7705_deinit(&gs_handle);
345
346 return 1;
347 }
348 ad7705_interface_debug_print("ad7705: set adc gain1.\n");
349 res = ad7705_get_adc_gain(&gs_handle, &gain);
350 if (res != 0)
351 {
352 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
353 (void)ad7705_deinit(&gs_handle);
354
355 return 1;
356 }
357 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_1) ? "ok" : "error");
358
359 /* set adc gain2 */
360 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_2);
361 if (res != 0)
362 {
363 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
364 (void)ad7705_deinit(&gs_handle);
365
366 return 1;
367 }
368 ad7705_interface_debug_print("ad7705: set adc gain2.\n");
369 res = ad7705_get_adc_gain(&gs_handle, &gain);
370 if (res != 0)
371 {
372 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
373 (void)ad7705_deinit(&gs_handle);
374
375 return 1;
376 }
377 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_2) ? "ok" : "error");
378
379 /* set adc gain4 */
380 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_4);
381 if (res != 0)
382 {
383 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
384 (void)ad7705_deinit(&gs_handle);
385
386 return 1;
387 }
388 ad7705_interface_debug_print("ad7705: set adc gain4.\n");
389 res = ad7705_get_adc_gain(&gs_handle, &gain);
390 if (res != 0)
391 {
392 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
393 (void)ad7705_deinit(&gs_handle);
394
395 return 1;
396 }
397 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_4) ? "ok" : "error");
398
399 /* set adc gain8 */
400 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_8);
401 if (res != 0)
402 {
403 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
404 (void)ad7705_deinit(&gs_handle);
405
406 return 1;
407 }
408 ad7705_interface_debug_print("ad7705: set adc gain8.\n");
409 res = ad7705_get_adc_gain(&gs_handle, &gain);
410 if (res != 0)
411 {
412 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
413 (void)ad7705_deinit(&gs_handle);
414
415 return 1;
416 }
417 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_8) ? "ok" : "error");
418
419 /* set adc gain16 */
420 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_16);
421 if (res != 0)
422 {
423 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
424 (void)ad7705_deinit(&gs_handle);
425
426 return 1;
427 }
428 ad7705_interface_debug_print("ad7705: set adc gain16.\n");
429 res = ad7705_get_adc_gain(&gs_handle, &gain);
430 if (res != 0)
431 {
432 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
433 (void)ad7705_deinit(&gs_handle);
434
435 return 1;
436 }
437 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_16) ? "ok" : "error");
438
439 /* set adc gain32 */
440 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_32);
441 if (res != 0)
442 {
443 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
444 (void)ad7705_deinit(&gs_handle);
445
446 return 1;
447 }
448 ad7705_interface_debug_print("ad7705: set adc gain32.\n");
449 res = ad7705_get_adc_gain(&gs_handle, &gain);
450 if (res != 0)
451 {
452 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
453 (void)ad7705_deinit(&gs_handle);
454
455 return 1;
456 }
457 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_32) ? "ok" : "error");
458
459 /* set adc gain64 */
460 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_64);
461 if (res != 0)
462 {
463 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
464 (void)ad7705_deinit(&gs_handle);
465
466 return 1;
467 }
468 ad7705_interface_debug_print("ad7705: set adc gain64.\n");
469 res = ad7705_get_adc_gain(&gs_handle, &gain);
470 if (res != 0)
471 {
472 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
473 (void)ad7705_deinit(&gs_handle);
474
475 return 1;
476 }
477 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_64) ? "ok" : "error");
478
479 /* set adc gain128 */
480 res = ad7705_set_adc_gain(&gs_handle, AD7705_ADC_GAIN_128);
481 if (res != 0)
482 {
483 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
484 (void)ad7705_deinit(&gs_handle);
485
486 return 1;
487 }
488 ad7705_interface_debug_print("ad7705: set adc gain128.\n");
489 res = ad7705_get_adc_gain(&gs_handle, &gain);
490 if (res != 0)
491 {
492 ad7705_interface_debug_print("ad7705: get adc gain failed.\n");
493 (void)ad7705_deinit(&gs_handle);
494
495 return 1;
496 }
497 ad7705_interface_debug_print("ad7705: check adc gain %s.\n", (gain == AD7705_ADC_GAIN_128) ? "ok" : "error");
498
499 /* ad7705_set_adc_polar/ad7705_get_adc_polar test */
500 ad7705_interface_debug_print("ad7705: ad7705_set_adc_polar/ad7705_get_adc_polar test.\n");
501
502 /* set adc bipolar */
504 if (res != 0)
505 {
506 ad7705_interface_debug_print("ad7705: set adc polar failed.\n");
507 (void)ad7705_deinit(&gs_handle);
508
509 return 1;
510 }
511 ad7705_interface_debug_print("ad7705: set adc bipolar.\n");
512 res = ad7705_get_adc_polar(&gs_handle, &polar);
513 if (res != 0)
514 {
515 ad7705_interface_debug_print("ad7705: get adc polar failed.\n");
516 (void)ad7705_deinit(&gs_handle);
517
518 return 1;
519 }
520 ad7705_interface_debug_print("ad7705: check adc polar %s.\n", (polar == AD7705_ADC_POLAR_BIPOLAR) ? "ok" : "error");
521
522 /* set adc unipolar */
524 if (res != 0)
525 {
526 ad7705_interface_debug_print("ad7705: set adc polar failed.\n");
527 (void)ad7705_deinit(&gs_handle);
528
529 return 1;
530 }
531 ad7705_interface_debug_print("ad7705: set adc unipolar.\n");
532 res = ad7705_get_adc_polar(&gs_handle, &polar);
533 if (res != 0)
534 {
535 ad7705_interface_debug_print("ad7705: get adc polar failed.\n");
536 (void)ad7705_deinit(&gs_handle);
537
538 return 1;
539 }
540 ad7705_interface_debug_print("ad7705: check adc polar %s.\n", (polar == AD7705_ADC_POLAR_UNIPOLAR) ? "ok" : "error");
541
542 /* ad7705_set_adc_buffer/ad7705_get_adc_buffer test */
543 ad7705_interface_debug_print("ad7705: ad7705_set_adc_buffer/ad7705_get_adc_buffer test.\n");
544
545 /* enable adc buffer */
546 res = ad7705_set_adc_buffer(&gs_handle, AD7705_BOOL_TRUE);
547 if (res != 0)
548 {
549 ad7705_interface_debug_print("ad7705: set adc buffer failed.\n");
550 (void)ad7705_deinit(&gs_handle);
551
552 return 1;
553 }
554 ad7705_interface_debug_print("ad7705: enable adc buffer.\n");
555 res = ad7705_get_adc_buffer(&gs_handle, &enable);
556 if (res != 0)
557 {
558 ad7705_interface_debug_print("ad7705: get adc buffer failed.\n");
559 (void)ad7705_deinit(&gs_handle);
560
561 return 1;
562 }
563 ad7705_interface_debug_print("ad7705: check adc buffer %s.\n", (enable == AD7705_BOOL_TRUE) ? "ok" : "error");
564
565 /* disable adc buffer */
566 res = ad7705_set_adc_buffer(&gs_handle, AD7705_BOOL_FALSE);
567 if (res != 0)
568 {
569 ad7705_interface_debug_print("ad7705: set adc buffer failed.\n");
570 (void)ad7705_deinit(&gs_handle);
571
572 return 1;
573 }
574 ad7705_interface_debug_print("ad7705: disable adc buffer.\n");
575 res = ad7705_get_adc_buffer(&gs_handle, &enable);
576 if (res != 0)
577 {
578 ad7705_interface_debug_print("ad7705: get adc buffer failed.\n");
579 (void)ad7705_deinit(&gs_handle);
580
581 return 1;
582 }
583 ad7705_interface_debug_print("ad7705: check adc buffer %s.\n", (enable == AD7705_BOOL_FALSE) ? "ok" : "error");
584
585 /* ad7705_set_filter_synchronize/ad7705_get_filter_synchronize test */
586 ad7705_interface_debug_print("ad7705: ad7705_set_filter_synchronize/ad7705_get_filter_synchronize test.\n");
587
588 /* enable filter synchronize */
590 if (res != 0)
591 {
592 ad7705_interface_debug_print("ad7705: set filter synchronize failed.\n");
593 (void)ad7705_deinit(&gs_handle);
594
595 return 1;
596 }
597 ad7705_interface_debug_print("ad7705: enable filter synchronize.\n");
598 res = ad7705_get_filter_synchronize(&gs_handle, &enable);
599 if (res != 0)
600 {
601 ad7705_interface_debug_print("ad7705: get filter synchronize failed.\n");
602 (void)ad7705_deinit(&gs_handle);
603
604 return 1;
605 }
606 ad7705_interface_debug_print("ad7705: check filter synchronize %s.\n", (enable == AD7705_BOOL_TRUE) ? "ok" : "error");
607
608 /* disable filter synchronize */
610 if (res != 0)
611 {
612 ad7705_interface_debug_print("ad7705: set filter synchronize failed.\n");
613 (void)ad7705_deinit(&gs_handle);
614
615 return 1;
616 }
617 ad7705_interface_debug_print("ad7705: disable filter synchronize.\n");
618 res = ad7705_get_filter_synchronize(&gs_handle, &enable);
619 if (res != 0)
620 {
621 ad7705_interface_debug_print("ad7705: get filter synchronize failed.\n");
622 (void)ad7705_deinit(&gs_handle);
623
624 return 1;
625 }
626 ad7705_interface_debug_print("ad7705: check filter synchronize %s.\n", (enable == AD7705_BOOL_FALSE) ? "ok" : "error");
627
628 /* ad7705_set_master_clock_output_disable/ad7705_get_master_clock_output_disable test */
629 ad7705_interface_debug_print("ad7705: ad7705_set_master_clock_output_disable/ad7705_get_master_clock_output_disable test.\n");
630
631 /* disable master clock output disable */
633 if (res != 0)
634 {
635 ad7705_interface_debug_print("ad7705: set master clock output disable failed.\n");
636 (void)ad7705_deinit(&gs_handle);
637
638 return 1;
639 }
640 ad7705_interface_debug_print("ad7705: disable master clock output disable.\n");
641 res = ad7705_get_master_clock_output_disable(&gs_handle, &enable);
642 if (res != 0)
643 {
644 ad7705_interface_debug_print("ad7705: get master clock output disable failed.\n");
645 (void)ad7705_deinit(&gs_handle);
646
647 return 1;
648 }
649 ad7705_interface_debug_print("ad7705: check master clock output disable %s.\n", (enable == AD7705_BOOL_FALSE) ? "ok" : "error");
650
651 /* enable master clock output disable */
653 if (res != 0)
654 {
655 ad7705_interface_debug_print("ad7705: set master clock output disable failed.\n");
656 (void)ad7705_deinit(&gs_handle);
657
658 return 1;
659 }
660 ad7705_interface_debug_print("ad7705: enable master clock output disable.\n");
661 res = ad7705_get_master_clock_output_disable(&gs_handle, &enable);
662 if (res != 0)
663 {
664 ad7705_interface_debug_print("ad7705: get master clock output disable failed.\n");
665 (void)ad7705_deinit(&gs_handle);
666
667 return 1;
668 }
669 ad7705_interface_debug_print("ad7705: check master clock output disable %s.\n", (enable == AD7705_BOOL_TRUE) ? "ok" : "error");
670
671 /* ad7705_set_clock_div2/ad7705_get_clock_div2 test */
672 ad7705_interface_debug_print("ad7705: ad7705_set_clock_div2/ad7705_get_clock_div2 test.\n");
673
674 /* enable clock div2 */
675 res = ad7705_set_clock_div2(&gs_handle, AD7705_BOOL_TRUE);
676 if (res != 0)
677 {
678 ad7705_interface_debug_print("ad7705: set clock div2 failed.\n");
679 (void)ad7705_deinit(&gs_handle);
680
681 return 1;
682 }
683 ad7705_interface_debug_print("ad7705: enable clock div2.\n");
684 res = ad7705_get_clock_div2(&gs_handle, &enable);
685 if (res != 0)
686 {
687 ad7705_interface_debug_print("ad7705: get clock div2 failed.\n");
688 (void)ad7705_deinit(&gs_handle);
689
690 return 1;
691 }
692 ad7705_interface_debug_print("ad7705: check clock div2 %s.\n", (enable == AD7705_BOOL_TRUE) ? "ok" : "error");
693
694 /* disable clock div2 */
695 res = ad7705_set_clock_div2(&gs_handle, AD7705_BOOL_FALSE);
696 if (res != 0)
697 {
698 ad7705_interface_debug_print("ad7705: set clock div2 failed.\n");
699 (void)ad7705_deinit(&gs_handle);
700
701 return 1;
702 }
703 ad7705_interface_debug_print("ad7705: disable clock div2.\n");
704 res = ad7705_get_clock_div2(&gs_handle, &enable);
705 if (res != 0)
706 {
707 ad7705_interface_debug_print("ad7705: get clock div2 failed.\n");
708 (void)ad7705_deinit(&gs_handle);
709
710 return 1;
711 }
712 ad7705_interface_debug_print("ad7705: check clock div2 %s.\n", (enable == AD7705_BOOL_FALSE) ? "ok" : "error");
713
714 /* ad7705_set_rate/ad7705_get_rate test */
715 ad7705_interface_debug_print("ad7705: ad7705_set_rate/ad7705_get_rate test.\n");
716
717 /* set rate 20hz */
718 res = ad7705_set_rate(&gs_handle, AD7705_RATE_20HZ);
719 if (res != 0)
720 {
721 ad7705_interface_debug_print("ad7705: set rate failed.\n");
722 (void)ad7705_deinit(&gs_handle);
723
724 return 1;
725 }
726 ad7705_interface_debug_print("ad7705: set rate 20hz.\n");
727 res = ad7705_get_rate(&gs_handle, &rate);
728 if (res != 0)
729 {
730 ad7705_interface_debug_print("ad7705: get rate failed.\n");
731 (void)ad7705_deinit(&gs_handle);
732
733 return 1;
734 }
735 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_20HZ) ? "ok" : "error");
736
737 /* set rate 25hz */
738 res = ad7705_set_rate(&gs_handle, AD7705_RATE_25HZ);
739 if (res != 0)
740 {
741 ad7705_interface_debug_print("ad7705: set rate failed.\n");
742 (void)ad7705_deinit(&gs_handle);
743
744 return 1;
745 }
746 ad7705_interface_debug_print("ad7705: set rate 25hz.\n");
747 res = ad7705_get_rate(&gs_handle, &rate);
748 if (res != 0)
749 {
750 ad7705_interface_debug_print("ad7705: get rate failed.\n");
751 (void)ad7705_deinit(&gs_handle);
752
753 return 1;
754 }
755 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_25HZ) ? "ok" : "error");
756
757 /* set rate 100hz */
758 res = ad7705_set_rate(&gs_handle, AD7705_RATE_100HZ);
759 if (res != 0)
760 {
761 ad7705_interface_debug_print("ad7705: set rate failed.\n");
762 (void)ad7705_deinit(&gs_handle);
763
764 return 1;
765 }
766 ad7705_interface_debug_print("ad7705: set rate 100hz.\n");
767 res = ad7705_get_rate(&gs_handle, &rate);
768 if (res != 0)
769 {
770 ad7705_interface_debug_print("ad7705: get rate failed.\n");
771 (void)ad7705_deinit(&gs_handle);
772
773 return 1;
774 }
775 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_100HZ) ? "ok" : "error");
776
777 /* set rate 200hz */
778 res = ad7705_set_rate(&gs_handle, AD7705_RATE_200HZ);
779 if (res != 0)
780 {
781 ad7705_interface_debug_print("ad7705: set rate failed.\n");
782 (void)ad7705_deinit(&gs_handle);
783
784 return 1;
785 }
786 ad7705_interface_debug_print("ad7705: set rate 200hz.\n");
787 res = ad7705_get_rate(&gs_handle, &rate);
788 if (res != 0)
789 {
790 ad7705_interface_debug_print("ad7705: get rate failed.\n");
791 (void)ad7705_deinit(&gs_handle);
792
793 return 1;
794 }
795 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_200HZ) ? "ok" : "error");
796
797 /* set rate 50hz */
798 res = ad7705_set_rate(&gs_handle, AD7705_RATE_50HZ);
799 if (res != 0)
800 {
801 ad7705_interface_debug_print("ad7705: set rate failed.\n");
802 (void)ad7705_deinit(&gs_handle);
803
804 return 1;
805 }
806 ad7705_interface_debug_print("ad7705: set rate 50hz.\n");
807 res = ad7705_get_rate(&gs_handle, &rate);
808 if (res != 0)
809 {
810 ad7705_interface_debug_print("ad7705: get rate failed.\n");
811 (void)ad7705_deinit(&gs_handle);
812
813 return 1;
814 }
815 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_50HZ) ? "ok" : "error");
816
817 /* set rate 60hz */
818 res = ad7705_set_rate(&gs_handle, AD7705_RATE_60HZ);
819 if (res != 0)
820 {
821 ad7705_interface_debug_print("ad7705: set rate failed.\n");
822 (void)ad7705_deinit(&gs_handle);
823
824 return 1;
825 }
826 ad7705_interface_debug_print("ad7705: set rate 60hz.\n");
827 res = ad7705_get_rate(&gs_handle, &rate);
828 if (res != 0)
829 {
830 ad7705_interface_debug_print("ad7705: get rate failed.\n");
831 (void)ad7705_deinit(&gs_handle);
832
833 return 1;
834 }
835 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_60HZ) ? "ok" : "error");
836
837 /* set rate 250hz */
838 res = ad7705_set_rate(&gs_handle, AD7705_RATE_250HZ);
839 if (res != 0)
840 {
841 ad7705_interface_debug_print("ad7705: set rate failed.\n");
842 (void)ad7705_deinit(&gs_handle);
843
844 return 1;
845 }
846 ad7705_interface_debug_print("ad7705: set rate 250hz.\n");
847 res = ad7705_get_rate(&gs_handle, &rate);
848 if (res != 0)
849 {
850 ad7705_interface_debug_print("ad7705: get rate failed.\n");
851 (void)ad7705_deinit(&gs_handle);
852
853 return 1;
854 }
855 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_250HZ) ? "ok" : "error");
856
857 /* set rate 500hz */
858 res = ad7705_set_rate(&gs_handle, AD7705_RATE_500HZ);
859 if (res != 0)
860 {
861 ad7705_interface_debug_print("ad7705: set rate failed.\n");
862 (void)ad7705_deinit(&gs_handle);
863
864 return 1;
865 }
866 ad7705_interface_debug_print("ad7705: set rate 500hz.\n");
867 res = ad7705_get_rate(&gs_handle, &rate);
868 if (res != 0)
869 {
870 ad7705_interface_debug_print("ad7705: get rate failed.\n");
871 (void)ad7705_deinit(&gs_handle);
872
873 return 1;
874 }
875 ad7705_interface_debug_print("ad7705: check rate %s.\n", (rate == AD7705_RATE_500HZ) ? "ok" : "error");
876
877 /* ad7705_set_test/ad7705_get_test test */
878 ad7705_interface_debug_print("ad7705: ad7705_set_test/ad7705_get_test test.\n");
879
880 data = 0x00;
881 res = ad7705_set_test(&gs_handle, data);
882 if (res != 0)
883 {
884 ad7705_interface_debug_print("ad7705: set test failed.\n");
885 (void)ad7705_deinit(&gs_handle);
886
887 return 1;
888 }
889 ad7705_interface_debug_print("ad7705: set test 0x%02X.\n", data);
890 res = ad7705_get_test(&gs_handle, &data_check);
891 if (res != 0)
892 {
893 ad7705_interface_debug_print("ad7705: get test failed.\n");
894 (void)ad7705_deinit(&gs_handle);
895
896 return 1;
897 }
898 ad7705_interface_debug_print("ad7705: check test %s.\n", (data == data_check) ? "ok" : "error");
899
900 /* ad7705_set_zero_scale_calibration/ad7705_get_zero_scale_calibration test */
901 ad7705_interface_debug_print("ad7705: ad7705_set_zero_scale_calibration/ad7705_get_zero_scale_calibration test.\n");
902
903 calibration = 0x000000;
904 res = ad7705_set_zero_scale_calibration(&gs_handle, calibration);
905 if (res != 0)
906 {
907 ad7705_interface_debug_print("ad7705: set zero scale calibration failed.\n");
908 (void)ad7705_deinit(&gs_handle);
909
910 return 1;
911 }
912 ad7705_interface_debug_print("ad7705: set zero scale calibration 0x%04X.\n", calibration);
913 res = ad7705_get_zero_scale_calibration(&gs_handle, &calibration_check);
914 if (res != 0)
915 {
916 ad7705_interface_debug_print("ad7705: get zero scale calibration failed.\n");
917 (void)ad7705_deinit(&gs_handle);
918
919 return 1;
920 }
921 ad7705_interface_debug_print("ad7705: check zero scale calibration %s.\n", (calibration == calibration_check) ? "ok" : "error");
922
923 /* ad7705_set_full_scale_calibration/ad7705_get_full_scale_calibration test */
924 ad7705_interface_debug_print("ad7705: ad7705_set_full_scale_calibration/ad7705_get_full_scale_calibration test.\n");
925
926 calibration = 0x000000;
927 res = ad7705_set_full_scale_calibration(&gs_handle, calibration);
928 if (res != 0)
929 {
930 ad7705_interface_debug_print("ad7705: set full scale calibration failed.\n");
931 (void)ad7705_deinit(&gs_handle);
932
933 return 1;
934 }
935 ad7705_interface_debug_print("ad7705: set full scale calibration 0x%04X.\n", calibration);
936 res = ad7705_get_full_scale_calibration(&gs_handle, &calibration_check);
937 if (res != 0)
938 {
939 ad7705_interface_debug_print("ad7705: get full scale calibration failed.\n");
940 (void)ad7705_deinit(&gs_handle);
941
942 return 1;
943 }
944 ad7705_interface_debug_print("ad7705: check full scale calibration %s.\n", (calibration == calibration_check) ? "ok" : "error");
945
946 /* ad7705_get_data test */
947 ad7705_interface_debug_print("ad7705: ad7705_get_data test.\n");
948
949 /* get data */
950 res = ad7705_get_data(&gs_handle, &adc_data);
951 if (res != 0)
952 {
953 ad7705_interface_debug_print("ad7705: get data failed.\n");
954 (void)ad7705_deinit(&gs_handle);
955
956 return 1;
957 }
958 ad7705_interface_debug_print("ad7705: data is 0x%04X.\n", adc_data);
959
960 /* ad7705_get_data_ready test */
961 ad7705_interface_debug_print("ad7705: ad7705_get_data_ready test.\n");
962
963 /* get data ready */
964 res = ad7705_get_data_ready(&gs_handle, &enable);
965 if (res != 0)
966 {
967 ad7705_interface_debug_print("ad7705: get data ready failed.\n");
968 (void)ad7705_deinit(&gs_handle);
969
970 return 1;
971 }
972 ad7705_interface_debug_print("ad7705: data ready is %s.\n", (enable == AD7705_BOOL_TRUE) ? "true" : "false");
973
974 /* ad7705_power_on test */
975 ad7705_interface_debug_print("ad7705: ad7705_power_on test.\n");
976
977 /* power on */
978 res = ad7705_power_on(&gs_handle);
979 if (res != 0)
980 {
981 ad7705_interface_debug_print("ad7705: power on failed.\n");
982 (void)ad7705_deinit(&gs_handle);
983
984 return 1;
985 }
986 ad7705_interface_debug_print("ad7705: check power on %s.\n", (res == 0) ? "ok" : "error");
987
988 /* ad7705_power_down test */
989 ad7705_interface_debug_print("ad7705: ad7705_power_down test.\n");
990
991 /* power down */
992 res = ad7705_power_down(&gs_handle);
993 if (res != 0)
994 {
995 ad7705_interface_debug_print("ad7705: power down failed.\n");
996 (void)ad7705_deinit(&gs_handle);
997
998 return 1;
999 }
1000 ad7705_interface_debug_print("ad7705: check power down %s.\n", (res == 0) ? "ok" : "error");
1001
1002 /* finish register */
1003 ad7705_interface_debug_print("ad7705: finish register test.\n");
1004 (void)ad7705_deinit(&gs_handle);
1005
1006 return 0;
1007}
driver ad7705 register test header file
uint8_t ad7705_set_full_scale_calibration(ad7705_handle_t *handle, uint32_t calibration)
set full scale calibration
uint8_t ad7705_get_adc_polar(ad7705_handle_t *handle, ad7705_adc_polar_t *polar)
get adc polar
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
ad7705_bool_t
ad7705 bool enumeration definition
uint8_t ad7705_get_channel(ad7705_handle_t *handle, ad7705_channel_t *channel)
get channel
struct ad7705_handle_s ad7705_handle_t
ad7705 handle structure definition
uint8_t ad7705_get_adc_buffer(ad7705_handle_t *handle, ad7705_bool_t *enable)
get adc buffer status
uint8_t ad7705_get_rate(ad7705_handle_t *handle, ad7705_rate_t *rate)
get rate
uint8_t ad7705_get_clock_div2(ad7705_handle_t *handle, ad7705_bool_t *enable)
get clock div2 status
ad7705_adc_mode_t
ad7705 adc mode enumeration definition
uint8_t ad7705_get_adc_gain(ad7705_handle_t *handle, ad7705_adc_gain_t *gain)
get adc gain
uint8_t ad7705_get_test(ad7705_handle_t *handle, uint8_t *data)
get test data
uint8_t ad7705_init(ad7705_handle_t *handle)
initialize the chip
uint8_t ad7705_get_full_scale_calibration(ad7705_handle_t *handle, uint32_t *calibration)
get full scale calibration
uint8_t ad7705_get_adc_mode(ad7705_handle_t *handle, ad7705_adc_mode_t *mode)
get adc mode
uint8_t ad7705_set_adc_buffer(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable adc buffer
uint8_t ad7705_get_data(ad7705_handle_t *handle, uint16_t *data)
get data
ad7705_adc_polar_t
ad7705 adc polar enumeration definition
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_zero_scale_calibration(ad7705_handle_t *handle, uint32_t calibration)
set zero scale calibration
uint8_t ad7705_set_rate(ad7705_handle_t *handle, ad7705_rate_t rate)
set rate
uint8_t ad7705_get_filter_synchronize(ad7705_handle_t *handle, ad7705_bool_t *enable)
get filter synchronize status
uint8_t ad7705_get_zero_scale_calibration(ad7705_handle_t *handle, uint32_t *calibration)
get zero scale calibration
uint8_t ad7705_get_data_ready(ad7705_handle_t *handle, ad7705_bool_t *enable)
get data ready
uint8_t ad7705_get_reference_voltage(ad7705_handle_t *handle, float *voltage)
get reference voltage
ad7705_rate_t
ad7705 rate enumeration definition
uint8_t ad7705_set_clock_div2(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable clock div2
uint8_t ad7705_power_down(ad7705_handle_t *handle)
power down
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_test(ad7705_handle_t *handle, uint8_t data)
set test data
uint8_t ad7705_set_channel(ad7705_handle_t *handle, ad7705_channel_t channel)
set channel
ad7705_adc_gain_t
ad7705 adc gain enumeration definition
uint8_t ad7705_info(ad7705_info_t *info)
get chip's information
uint8_t ad7705_get_master_clock_output_disable(ad7705_handle_t *handle, ad7705_bool_t *enable)
get master clock output disable status
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_CHANNEL_AIN2_POSITIVE_AIN2_NEGATIVE
@ AD7705_CHANNEL_AIN1_NEGATIVE_AIN1_NEGATIVE
@ AD7705_CHANNEL_AIN1_POSITIVE_AIN1_NEGATIVE
@ AD7705_CHANNEL_AIN1_NEGATIVE_AIN2_NEGATIVE
@ AD7705_BOOL_FALSE
@ AD7705_BOOL_TRUE
@ AD7705_ADC_MODE_SELF_CALIBRATION
@ AD7705_ADC_MODE_NORMAL
@ AD7705_ADC_MODE_FULL_SCALE_SYSTEM_CALIBRATION
@ AD7705_ADC_MODE_ZERO_SCALE_SYSTEM_CALIBRATION
@ AD7705_ADC_POLAR_UNIPOLAR
@ AD7705_ADC_POLAR_BIPOLAR
@ AD7705_RATE_100HZ
@ AD7705_RATE_250HZ
@ AD7705_RATE_200HZ
@ AD7705_RATE_50HZ
@ AD7705_RATE_20HZ
@ AD7705_RATE_25HZ
@ AD7705_RATE_500HZ
@ AD7705_RATE_60HZ
@ 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_register_test(void)
register test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]