LibDriver ADS1115
Loading...
Searching...
No Matches
driver_ads1115_register_test.c
Go to the documentation of this file.
1
37
39#include <stdlib.h>
40
41static ads1115_handle_t gs_handle;
42
52{
53 uint8_t res;
54 int16_t high_threshold;
55 int16_t low_threshold;
56 int16_t high_threshold_before;
57 int16_t low_threshold_before;
58 int16_t reg;
59 float f_reg;
60 float f_reg_check;
61 ads1115_info_t info;
62 ads1115_channel_t channel;
63 ads1115_range_t range;
64 ads1115_pin_t pin;
65 ads1115_compare_t compare;
66 ads1115_rate_t rate;
67 ads1115_comparator_queue_t comparator_queue;
68 ads1115_address_t addr_pin;
69 ads1115_bool_t enable;
70
71 /* link interface function */
79
80 /* get information */
81 res = ads1115_info(&info);
82 if (res != 0)
83 {
84 ads1115_interface_debug_print("ads1115: get info failed.\n");
85
86 return 1;
87 }
88 else
89 {
90 /* print chip info */
91 ads1115_interface_debug_print("ads1115: chip is %s.\n", info.chip_name);
92 ads1115_interface_debug_print("ads1115: manufacturer is %s.\n", info.manufacturer_name);
93 ads1115_interface_debug_print("ads1115: interface is %s.\n", info.interface);
94 ads1115_interface_debug_print("ads1115: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
95 ads1115_interface_debug_print("ads1115: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
96 ads1115_interface_debug_print("ads1115: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
97 ads1115_interface_debug_print("ads1115: max current is %0.2fmA.\n", info.max_current_ma);
98 ads1115_interface_debug_print("ads1115: max temperature is %0.1fC.\n", info.temperature_max);
99 ads1115_interface_debug_print("ads1115: min temperature is %0.1fC.\n", info.temperature_min);
100 }
101
102 /* start register test */
103 ads1115_interface_debug_print("ads1115: start register test.\n");
104
105 /* ads1115_set_addr_pin/ads1115_get_addr_pin test */
106 ads1115_interface_debug_print("ads1115: ads1115_set_addr_pin/ads1115_get_addr_pin test.\n");
107
108 /* set ADDR_GND */
109 res = ads1115_set_addr_pin(&gs_handle, ADS1115_ADDR_GND);
110 if (res != 0)
111 {
112 ads1115_interface_debug_print("ads1115: set addr pin failed.\n");
113
114 return 1;
115 }
116 ads1115_interface_debug_print("ads1115: set addr pin ground.\n");
117 res = ads1115_get_addr_pin(&gs_handle, &addr_pin);
118 if (res != 0)
119 {
120 ads1115_interface_debug_print("ads1115: get addr pin failed.\n");
121
122 return 1;
123 }
124 ads1115_interface_debug_print("ads1115: check addr pin %s.\n", addr_pin == ADS1115_ADDR_GND ? "ok" : "error");
125
126 /* set ADDR_VCC */
127 res = ads1115_set_addr_pin(&gs_handle, ADS1115_ADDR_VCC);
128 if (res != 0)
129 {
130 ads1115_interface_debug_print("ads1115: set addr pin failed.\n");
131
132 return 1;
133 }
134 ads1115_interface_debug_print("ads1115: set addr pin vcc.\n");
135 res = ads1115_get_addr_pin(&gs_handle, &addr_pin);
136 if (res != 0)
137 {
138 ads1115_interface_debug_print("ads1115: get addr pin failed.\n");
139
140 return 1;
141 }
142 ads1115_interface_debug_print("ads1115: check addr pin %s.\n", addr_pin == ADS1115_ADDR_VCC ? "ok" : "error");
143
144 /* set ADDR_SDA */
145 res = ads1115_set_addr_pin(&gs_handle, ADS1115_ADDR_SDA);
146 if (res != 0)
147 {
148 ads1115_interface_debug_print("ads1115: set addr pin failed.\n");
149
150 return 1;
151 }
152 ads1115_interface_debug_print("ads1115: set addr pin sda.\n");
153 res = ads1115_get_addr_pin(&gs_handle, &addr_pin);
154 if (res != 0)
155 {
156 ads1115_interface_debug_print("ads1115: get addr pin failed.\n");
157
158 return 1;
159 }
160 ads1115_interface_debug_print("ads1115: check addr pin %s.\n", addr_pin == ADS1115_ADDR_SDA ? "ok" : "error");
161
162 /* set ADDR_SCL */
163 res = ads1115_set_addr_pin(&gs_handle, ADS1115_ADDR_SCL);
164 if (res != 0)
165 {
166 ads1115_interface_debug_print("ads1115: set addr pin failed.\n");
167
168 return 1;
169 }
170 ads1115_interface_debug_print("ads1115: set addr pin scl.\n");
171 res = ads1115_get_addr_pin(&gs_handle, &addr_pin);
172 if (res != 0)
173 {
174 ads1115_interface_debug_print("ads1115: get addr pin failed.\n");
175
176 return 1;
177 }
178 ads1115_interface_debug_print("ads1115: check addr pin %s.\n", addr_pin == ADS1115_ADDR_SCL ? "ok" : "error");
179
180 /* set addr pin */
181 res = ads1115_set_addr_pin(&gs_handle, addr);
182 if (res != 0)
183 {
184 ads1115_interface_debug_print("ads1115: set addr failed.\n");
185
186 return 1;
187 }
188
189 /* ads1115 init */
190 res = ads1115_init(&gs_handle);
191 if (res != 0)
192 {
193 ads1115_interface_debug_print("ads1115: init failed.\n");
194
195 return 1;
196 }
197
198 /* ads1115_set_channel/ads1115_get_channel test */
199 ads1115_interface_debug_print("ads1115: ads1115_set_channel/ads1115_get_channel test.\n");
200
201 /* AIN0 to GND */
203 if (res != 0)
204 {
205 ads1115_interface_debug_print("ads1115: set channel failed.\n");
206 (void)ads1115_deinit(&gs_handle);
207
208 return 1;
209 }
210 ads1115_interface_debug_print("ads1115: set channel ain0_ground.\n");
211 res = ads1115_get_channel(&gs_handle, &channel);
212 if (res != 0)
213 {
214 ads1115_interface_debug_print("ads1115: get channel failed.\n");
215 (void)ads1115_deinit(&gs_handle);
216
217 return 1;
218 }
219 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN0_GND ? "ok" : "error");
220
221 /* AIN1 to GND */
223 if (res != 0)
224 {
225 ads1115_interface_debug_print("ads1115: set channel failed.\n");
226 (void)ads1115_deinit(&gs_handle);
227
228 return 1;
229 }
230 ads1115_interface_debug_print("ads1115: set channel ain1_ground.\n");
231 res = ads1115_get_channel(&gs_handle, &channel);
232 if (res != 0)
233 {
234 ads1115_interface_debug_print("ads1115: get channel failed.\n");
235 (void)ads1115_deinit(&gs_handle);
236
237 return 1;
238 }
239 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN1_GND ? "ok" : "error");
240
241 /* AIN2 to GND */
243 if (res != 0)
244 {
245 ads1115_interface_debug_print("ads1115: set channel failed.\n");
246 (void)ads1115_deinit(&gs_handle);
247
248 return 1;
249 }
250 ads1115_interface_debug_print("ads1115: set channel ain2_ground.\n");
251 res = ads1115_get_channel(&gs_handle, &channel);
252 if (res != 0)
253 {
254 ads1115_interface_debug_print("ads1115: get channel failed.\n");
255 (void)ads1115_deinit(&gs_handle);
256
257 return 1;
258 }
259 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN2_GND ? "ok" : "error");
260
261 /* AIN3 to GND */
263 if (res != 0)
264 {
265 ads1115_interface_debug_print("ads1115: set channel failed.\n");
266 (void)ads1115_deinit(&gs_handle);
267
268 return 1;
269 }
270 ads1115_interface_debug_print("ads1115: set channel ain3_ground.\n");
271 res = ads1115_get_channel(&gs_handle, &channel);
272 if (res != 0)
273 {
274 ads1115_interface_debug_print("ads1115: get channel failed.\n");
275 (void)ads1115_deinit(&gs_handle);
276
277 return 1;
278 }
279 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN3_GND ? "ok" : "error");
280
281 /* AIN0 to AIN1 */
283 if (res != 0)
284 {
285 ads1115_interface_debug_print("ads1115: set channel failed.\n");
286 (void)ads1115_deinit(&gs_handle);
287
288 return 1;
289 }
290 ads1115_interface_debug_print("ads1115: set channel ain0_ain1.\n");
291 res = ads1115_get_channel(&gs_handle, &channel);
292 if (res != 0)
293 {
294 ads1115_interface_debug_print("ads1115: get channel failed.\n");
295 (void)ads1115_deinit(&gs_handle);
296
297 return 1;
298 }
299 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN0_AIN1 ? "ok" : "error");
300
301 /* AIN0 to AIN3 */
303 if (res != 0)
304 {
305 ads1115_interface_debug_print("ads1115: set channel failed.\n");
306 (void)ads1115_deinit(&gs_handle);
307
308 return 1;
309 }
310 ads1115_interface_debug_print("ads1115: set channel ain0_ain3.\n");
311 res = ads1115_get_channel(&gs_handle, &channel);
312 if (res != 0)
313 {
314 ads1115_interface_debug_print("ads1115: get channel failed.\n");
315 (void)ads1115_deinit(&gs_handle);
316
317 return 1;
318 }
319 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN0_AIN3 ? "ok" : "error");
320
321 /* AIN1 to AIN3 */
323 if (res != 0)
324 {
325 ads1115_interface_debug_print("ads1115: set channel failed.\n");
326 (void)ads1115_deinit(&gs_handle);
327
328 return 1;
329 }
330 ads1115_interface_debug_print("ads1115: set channel ain1_ain3.\n");
331 res = ads1115_get_channel(&gs_handle, &channel);
332 if (res != 0)
333 {
334 ads1115_interface_debug_print("ads1115: get channel failed.\n");
335 (void)ads1115_deinit(&gs_handle);
336
337 return 1;
338 }
339 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN1_AIN3 ? "ok" : "error");
340
341 /* AIN2 to AIN3 */
343 if (res != 0)
344 {
345 ads1115_interface_debug_print("ads1115: set channel failed.\n");
346 (void)ads1115_deinit(&gs_handle);
347
348 return 1;
349 }
350 ads1115_interface_debug_print("ads1115: set channel ain2_ain3.\n");
351 res = ads1115_get_channel(&gs_handle, &channel);
352 if (res != 0)
353 {
354 ads1115_interface_debug_print("ads1115: get channel failed.\n");
355 (void)ads1115_deinit(&gs_handle);
356
357 return 1;
358 }
359 ads1115_interface_debug_print("ads1115: check channel %s.\n", channel == ADS1115_CHANNEL_AIN2_AIN3 ? "ok" : "error");
360
361 /* ads1115_set_range/ads1115_get_range test */
362 ads1115_interface_debug_print("ads1115: ads1115_set_range/ads1115_get_range test.\n");
363
364 /* set 6.144V */
365 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_6P144V);
366 if (res != 0)
367 {
368 ads1115_interface_debug_print("ads1115: set range failed.\n");
369 (void)ads1115_deinit(&gs_handle);
370
371 return 1;
372 }
373 ads1115_interface_debug_print("ads1115: set range 6.144V.\n");
374 res = ads1115_get_range(&gs_handle, &range);
375 if (res != 0)
376 {
377 ads1115_interface_debug_print("ads1115: get range failed.\n");
378 (void)ads1115_deinit(&gs_handle);
379
380 return 1;
381 }
382 ads1115_interface_debug_print("ads1115: check range %s.\n", range == ADS1115_RANGE_6P144V ? "ok" : "error");
383
384 /* set 4.096V */
385 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_4P096V);
386 if (res != 0)
387 {
388 ads1115_interface_debug_print("ads1115: set range failed.\n");
389 (void)ads1115_deinit(&gs_handle);
390
391 return 1;
392 }
393 ads1115_interface_debug_print("ads1115: set range 4.096V.\n");
394 res = ads1115_get_range(&gs_handle, &range);
395 if (res != 0)
396 {
397 ads1115_interface_debug_print("ads1115: get range failed.\n");
398 (void)ads1115_deinit(&gs_handle);
399
400 return 1;
401 }
402 ads1115_interface_debug_print("ads1115: check range %s.\n", range == ADS1115_RANGE_4P096V ? "ok" : "error");
403
404 /* set 2.048V */
405 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_2P048V);
406 if (res != 0)
407 {
408 ads1115_interface_debug_print("ads1115: set range failed.\n");
409 (void)ads1115_deinit(&gs_handle);
410
411 return 1;
412 }
413 ads1115_interface_debug_print("ads1115: set range 2.048V.\n");
414 res = ads1115_get_range(&gs_handle, &range);
415 if (res != 0)
416 {
417 ads1115_interface_debug_print("ads1115: get range failed.\n");
418 (void)ads1115_deinit(&gs_handle);
419
420 return 1;
421 }
422 ads1115_interface_debug_print("ads1115: check range %s.\n", range == ADS1115_RANGE_2P048V ? "ok" : "error");
423
424 /* set 1.024V */
425 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_1P024V);
426 if (res != 0)
427 {
428 ads1115_interface_debug_print("ads1115: set range failed.\n");
429 (void)ads1115_deinit(&gs_handle);
430
431 return 1;
432 }
433 ads1115_interface_debug_print("ads1115: set range 1.024V.\n");
434 res = ads1115_get_range(&gs_handle, &range);
435 if (res != 0)
436 {
437 ads1115_interface_debug_print("ads1115: get range failed.\n");
438 (void)ads1115_deinit(&gs_handle);
439
440 return 1;
441 }
442 ads1115_interface_debug_print("ads1115: check range %s.\n", range == ADS1115_RANGE_1P024V ? "ok" : "error");
443
444 /* set 0.512V */
445 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_0P512V);
446 if (res != 0)
447 {
448 ads1115_interface_debug_print("ads1115: set range failed.\n");
449 (void)ads1115_deinit(&gs_handle);
450
451 return 1;
452 }
453 ads1115_interface_debug_print("ads1115: set range 0.512V.\n");
454 res = ads1115_get_range(&gs_handle, &range);
455 if (res != 0)
456 {
457 ads1115_interface_debug_print("ads1115: get range failed.\n");
458 (void)ads1115_deinit(&gs_handle);
459
460 return 1;
461 }
462 ads1115_interface_debug_print("ads1115: check range %s.\n", range == ADS1115_RANGE_0P512V ? "ok" : "error");
463
464 /* set 0.256V */
465 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_0P256V);
466 if (res != 0)
467 {
468 ads1115_interface_debug_print("ads1115: set range failed.\n");
469 (void)ads1115_deinit(&gs_handle);
470
471 return 1;
472 }
473 ads1115_interface_debug_print("ads1115: set range 0.256V.\n");
474 res = ads1115_get_range(&gs_handle, &range);
475 if (res != 0)
476 {
477 ads1115_interface_debug_print("ads1115: get range failed.\n");
478 (void)ads1115_deinit(&gs_handle);
479
480 return 1;
481 }
482 ads1115_interface_debug_print("ads1115: check range %s.\n", range == ADS1115_RANGE_0P256V ? "ok" : "error");
483
484 /* ads1115_set_alert_pin/ads1115_get_alert_pin test */
485 ads1115_interface_debug_print("ads1115: ads1115_set_alert_pin/ads1115_get_alert_pin test.\n");
486
487 /* pin_low */
488 res = ads1115_set_alert_pin(&gs_handle, ADS1115_PIN_LOW);
489 if (res != 0)
490 {
491 ads1115_interface_debug_print("ads1115: set alert pin failed.\n");
492 (void)ads1115_deinit(&gs_handle);
493
494 return 1;
495 }
496 ads1115_interface_debug_print("ads1115: set alert pin low.\n");
497 res = ads1115_get_alert_pin(&gs_handle, &pin);
498 if (res != 0)
499 {
500 ads1115_interface_debug_print("ads1115: get alert pin failed.\n");
501 (void)ads1115_deinit(&gs_handle);
502
503 return 1;
504 }
505 ads1115_interface_debug_print("ads1115: check alert pin %s.\n", pin == ADS1115_PIN_LOW ? "ok" : "error");
506
507 /* pin_high */
508 res = ads1115_set_alert_pin(&gs_handle, ADS1115_PIN_HIGH);
509 if (res != 0)
510 {
511 ads1115_interface_debug_print("ads1115: set alert pin failed.\n");
512 (void)ads1115_deinit(&gs_handle);
513
514 return 1;
515 }
516 ads1115_interface_debug_print("ads1115: set alert pin high.\n");
517 res = ads1115_get_alert_pin(&gs_handle, &pin);
518 if (res != 0)
519 {
520 ads1115_interface_debug_print("ads1115: get alert pin failed.\n");
521 (void)ads1115_deinit(&gs_handle);
522
523 return 1;
524 }
525 ads1115_interface_debug_print("ads1115: check alert pin %s.\n", pin == ADS1115_PIN_HIGH ? "ok" : "error");
526
527 /* ads1115_set_compare_mode/ads1115_get_compare_mode test */
528 ads1115_interface_debug_print("ads1115: ads1115_set_compare_mode/ads1115_get_compare_mode test.\n");
529
530 /* set threshold */
532 if (res != 0)
533 {
534 ads1115_interface_debug_print("ads1115: set compare failed.\n");
535 (void)ads1115_deinit(&gs_handle);
536
537 return 1;
538 }
539 ads1115_interface_debug_print("ads1115: set compare threshold.\n");
540 res = ads1115_get_compare_mode(&gs_handle, &compare);
541 if (res != 0)
542 {
543 ads1115_interface_debug_print("ads1115: get compare failed.\n");
544 (void)ads1115_deinit(&gs_handle);
545
546 return 1;
547 }
548 ads1115_interface_debug_print("ads1115: check compare %s.\n", compare == ADS1115_COMPARE_THRESHOLD ? "ok" : "error");
549
550 /* set window */
552 if (res != 0)
553 {
554 ads1115_interface_debug_print("ads1115: set compare failed.\n");
555 (void)ads1115_deinit(&gs_handle);
556
557 return 1;
558 }
559 ads1115_interface_debug_print("ads1115: set compare window.\n");
560 res = ads1115_get_compare_mode(&gs_handle, &compare);
561 if (res != 0)
562 {
563 ads1115_interface_debug_print("ads1115: get compare failed.\n");
564 (void)ads1115_deinit(&gs_handle);
565
566 return 1;
567 }
568 ads1115_interface_debug_print("ads1115: check compare %s.\n", compare == ADS1115_COMPARE_WINDOW ? "ok" : "error");
569
570 /* ads1115_set_rate/ads1115_get_rate test */
571 ads1115_interface_debug_print("ads1115: ads1115_set_rate/ads1115_get_rate test.\n");
572
573 /* set 8SPS */
574 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_8SPS);
575 if (res != 0)
576 {
577 ads1115_interface_debug_print("ads1115: set rate failed.\n");
578 (void)ads1115_deinit(&gs_handle);
579
580 return 1;
581 }
582 ads1115_interface_debug_print("ads1115: set rate 8 sps.\n");
583 res = ads1115_get_rate(&gs_handle, &rate);
584 if (res != 0)
585 {
586 ads1115_interface_debug_print("ads1115: get rate failed.\n");
587 (void)ads1115_deinit(&gs_handle);
588
589 return 1;
590 }
591 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_8SPS ? "ok" : "error");
592
593 /* set 16SPS */
594 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_16SPS);
595 if (res != 0)
596 {
597 ads1115_interface_debug_print("ads1115: set rate failed.\n");
598 (void)ads1115_deinit(&gs_handle);
599
600 return 1;
601 }
602 ads1115_interface_debug_print("ads1115: set rate 16 sps.\n");
603 res = ads1115_get_rate(&gs_handle, &rate);
604 if (res != 0)
605 {
606 ads1115_interface_debug_print("ads1115: get rate failed.\n");
607 (void)ads1115_deinit(&gs_handle);
608
609 return 1;
610 }
611 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_16SPS ? "ok" : "error");
612
613 /* set 32SPS */
614 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_32SPS);
615 if (res != 0)
616 {
617 ads1115_interface_debug_print("ads1115: set rate failed.\n");
618 (void)ads1115_deinit(&gs_handle);
619
620 return 1;
621 }
622 ads1115_interface_debug_print("ads1115: set rate 32 sps.\n");
623 res = ads1115_get_rate(&gs_handle, &rate);
624 if (res != 0)
625 {
626 ads1115_interface_debug_print("ads1115: get rate failed.\n");
627 (void)ads1115_deinit(&gs_handle);
628
629 return 1;
630 }
631 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_32SPS ? "ok" : "error");
632
633 /* set 64SPS */
634 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_64SPS);
635 if (res != 0)
636 {
637 ads1115_interface_debug_print("ads1115: set rate failed.\n");
638 (void)ads1115_deinit(&gs_handle);
639
640 return 1;
641 }
642 ads1115_interface_debug_print("ads1115: set rate 64 sps.\n");
643 res = ads1115_get_rate(&gs_handle, &rate);
644 if (res != 0)
645 {
646 ads1115_interface_debug_print("ads1115: get rate failed.\n");
647 (void)ads1115_deinit(&gs_handle);
648
649 return 1;
650 }
651 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_64SPS ? "ok" : "error");
652
653 /* set 128SPS */
654 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_128SPS);
655 if (res != 0)
656 {
657 ads1115_interface_debug_print("ads1115: set rate failed.\n");
658 (void)ads1115_deinit(&gs_handle);
659
660 return 1;
661 }
662 ads1115_interface_debug_print("ads1115: set rate 128 sps.\n");
663 res = ads1115_get_rate(&gs_handle, &rate);
664 if (res != 0)
665 {
666 ads1115_interface_debug_print("ads1115: get rate failed.\n");
667 (void)ads1115_deinit(&gs_handle);
668
669 return 1;
670 }
671 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_128SPS ? "ok" : "error");
672
673 /* set 250SPS */
674 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_250SPS);
675 if (res != 0)
676 {
677 ads1115_interface_debug_print("ads1115: set rate failed.\n");
678 (void)ads1115_deinit(&gs_handle);
679
680 return 1;
681 }
682 ads1115_interface_debug_print("ads1115: set rate 250 sps.\n");
683 res = ads1115_get_rate(&gs_handle, &rate);
684 if (res != 0)
685 {
686 ads1115_interface_debug_print("ads1115: get rate failed.\n");
687 (void)ads1115_deinit(&gs_handle);
688
689 return 1;
690 }
691 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_250SPS ? "ok" : "error");
692
693 /* set 475SPS */
694 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_475SPS);
695 if (res != 0)
696 {
697 ads1115_interface_debug_print("ads1115: set rate failed.\n");
698 (void)ads1115_deinit(&gs_handle);
699
700 return 1;
701 }
702 ads1115_interface_debug_print("ads1115: set rate 475 sps.\n");
703 res = ads1115_get_rate(&gs_handle, &rate);
704 if (res != 0)
705 {
706 ads1115_interface_debug_print("ads1115: get rate failed.\n");
707 (void)ads1115_deinit(&gs_handle);
708
709 return 1;
710 }
711 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_475SPS ? "ok" : "error");
712
713 /* set 860SPS */
714 res = ads1115_set_rate(&gs_handle, ADS1115_RATE_860SPS);
715 if (res != 0)
716 {
717 ads1115_interface_debug_print("ads1115: set rate failed.\n");
718 (void)ads1115_deinit(&gs_handle);
719
720 return 1;
721 }
722 ads1115_interface_debug_print("ads1115: set rate 860 sps.\n");
723 res = ads1115_get_rate(&gs_handle, &rate);
724 if (res != 0)
725 {
726 ads1115_interface_debug_print("ads1115: get rate failed.\n");
727 (void)ads1115_deinit(&gs_handle);
728
729 return 1;
730 }
731 ads1115_interface_debug_print("ads1115: check rate %s.\n", rate == ADS1115_RATE_860SPS ? "ok" : "error");
732
733 /* ads1115_set_comparator_queue/ads1115_get_comparator_queue test */
734 ads1115_interface_debug_print("ads1115: ads1115_set_comparator_queue/ads1115_get_comparator_queue test.\n");
735
736 /* none conv */
738 if (res != 0)
739 {
740 ads1115_interface_debug_print("ads1115: set comparator queue failed.\n");
741 (void)ads1115_deinit(&gs_handle);
742
743 return 1;
744 }
745 ads1115_interface_debug_print("ads1115: set comparator queue none.\n");
746 res = ads1115_get_comparator_queue(&gs_handle, &comparator_queue);
747 if (res != 0)
748 {
749 ads1115_interface_debug_print("ads1115: get comparator queue failed.\n");
750 (void)ads1115_deinit(&gs_handle);
751
752 return 1;
753 }
754 ads1115_interface_debug_print("ads1115: check comparator queue %s.\n", comparator_queue == ADS1115_COMPARATOR_QUEUE_NONE_CONV ? "ok" : "error");
755
756 /* 1 conv */
758 if (res != 0)
759 {
760 ads1115_interface_debug_print("ads1115: set comparator queue failed.\n");
761 (void)ads1115_deinit(&gs_handle);
762
763 return 1;
764 }
765 ads1115_interface_debug_print("ads1115: set comparator queue 1 conv.\n");
766 res = ads1115_get_comparator_queue(&gs_handle, &comparator_queue);
767 if (res != 0)
768 {
769 ads1115_interface_debug_print("ads1115: get comparator queue failed.\n");
770 (void)ads1115_deinit(&gs_handle);
771
772 return 1;
773 }
774 ads1115_interface_debug_print("ads1115: check comparator queue %s.\n", comparator_queue == ADS1115_COMPARATOR_QUEUE_1_CONV ? "ok" : "error");
775
776 /* 2 conv */
778 if (res != 0)
779 {
780 ads1115_interface_debug_print("ads1115: set comparator queue failed.\n");
781 (void)ads1115_deinit(&gs_handle);
782
783 return 1;
784 }
785 ads1115_interface_debug_print("ads1115: set comparator queue 2 conv.\n");
786 res = ads1115_get_comparator_queue(&gs_handle, &comparator_queue);
787 if (res != 0)
788 {
789 ads1115_interface_debug_print("ads1115: get comparator queue failed.\n");
790 (void)ads1115_deinit(&gs_handle);
791
792 return 1;
793 }
794 ads1115_interface_debug_print("ads1115: check comparator queue %s.\n", comparator_queue == ADS1115_COMPARATOR_QUEUE_2_CONV ? "ok" : "error");
795
796 /* 4 conv */
798 if (res != 0)
799 {
800 ads1115_interface_debug_print("ads1115: set comparator queue failed.\n");
801 (void)ads1115_deinit(&gs_handle);
802
803 return 1;
804 }
805 ads1115_interface_debug_print("ads1115: set comparator queue 4 conv.\n");
806 res = ads1115_get_comparator_queue(&gs_handle, &comparator_queue);
807 if (res != 0)
808 {
809 ads1115_interface_debug_print("ads1115: get comparator queue failed.\n");
810 (void)ads1115_deinit(&gs_handle);
811
812 return 1;
813 }
814 ads1115_interface_debug_print("ads1115: check comparator queue %s.\n", comparator_queue == ADS1115_COMPARATOR_QUEUE_4_CONV ? "ok" : "error");
815
816 /* ads1115_set_compare_threshold/ads1115_get_compare_threshold test */
817 ads1115_interface_debug_print("ads1115: ads1115_set_compare_threshold/ads1115_get_compare_threshold test.\n");
818 high_threshold_before = rand() % 8196;
819 low_threshold_before = -rand() % 8196;
820 res = ads1115_set_compare_threshold(&gs_handle, high_threshold_before, low_threshold_before);
821 if (res != 0)
822 {
823 ads1115_interface_debug_print("ads1115: set compare threshold failed.\n");
824 (void)ads1115_deinit(&gs_handle);
825
826 return 1;
827 }
828 ads1115_interface_debug_print("ads1115: set high threshold %d low threshold %d.\n", high_threshold_before, low_threshold_before);
829 res = ads1115_get_compare_threshold(&gs_handle, (int16_t *)&high_threshold, (int16_t *)&low_threshold);
830 if (res != 0)
831 {
832 ads1115_interface_debug_print("ads1115: get compare threshold failed.\n");
833 (void)ads1115_deinit(&gs_handle);
834
835 return 1;
836 }
837 ads1115_interface_debug_print("ads1115: check high threshold %s.\n", high_threshold == high_threshold_before ? "ok" : "error");
838 ads1115_interface_debug_print("ads1115: check low threshold %s.\n", low_threshold == low_threshold_before ? "ok" : "error");
839
840 /* ads1115_set_compare/ads1115_get_compare test */
841 ads1115_interface_debug_print("ads1115: ads1115_set_compare/ads1115_get_compare test.\n");
842
843 /* enable compare */
844 res = ads1115_set_compare(&gs_handle, ADS1115_BOOL_TRUE);
845 if (res != 0)
846 {
847 ads1115_interface_debug_print("ads1115: set compare failed.\n");
848 (void)ads1115_deinit(&gs_handle);
849
850 return 1;
851 }
852 ads1115_interface_debug_print("ads1115: enable compare.\n");
853 res = ads1115_get_compare(&gs_handle, (ads1115_bool_t *)&enable);
854 if (res != 0)
855 {
856 ads1115_interface_debug_print("ads1115: get compare failed.\n");
857 (void)ads1115_deinit(&gs_handle);
858
859 return 1;
860 }
861 ads1115_interface_debug_print("ads1115: check compare %s.\n", enable == ADS1115_BOOL_TRUE ? "ok" : "error");
862
863 /* disable compare */
864 res = ads1115_set_compare(&gs_handle, ADS1115_BOOL_FALSE);
865 if (res != 0)
866 {
867 ads1115_interface_debug_print("ads1115: set compare failed.\n");
868 (void)ads1115_deinit(&gs_handle);
869
870 return 1;
871 }
872 ads1115_interface_debug_print("ads1115: disable compare.\n");
873 res = ads1115_get_compare(&gs_handle, (ads1115_bool_t *)&enable);
874 if (res != 0)
875 {
876 ads1115_interface_debug_print("ads1115: get compare failed.\n");
877 (void)ads1115_deinit(&gs_handle);
878
879 return 1;
880 }
881 ads1115_interface_debug_print("ads1115: check compare %s.\n", enable == ADS1115_BOOL_FALSE ? "ok" : "error");
882
883 /* ads1115_convert_to_register test */
884 ads1115_interface_debug_print("ads1115: ads1115_convert_to_register test.\n");
885
886 /* set 6.144V */
887 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_6P144V);
888 if (res != 0)
889 {
890 ads1115_interface_debug_print("ads1115: set range failed.\n");
891 (void)ads1115_deinit(&gs_handle);
892
893 return 1;
894 }
895 f_reg = -(rand() % 6144) / 1000.0f;
896 ads1115_interface_debug_print("ads1115: convert to register %0.2fV.\n", f_reg);
897 res = ads1115_convert_to_register(&gs_handle, f_reg, (int16_t *)&reg);
898 if (res != 0)
899 {
900 ads1115_interface_debug_print("ads1115: convert to register failed.\n");
901 (void)ads1115_deinit(&gs_handle);
902
903 return 1;
904 }
905 ads1115_interface_debug_print("ads1115: check convert to register %s.\n", reg == (int16_t)(f_reg * 32768.0f / 6.144f) ? "ok" : "error");
906
907 /* set 4.096V */
908 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_4P096V);
909 if (res != 0)
910 {
911 ads1115_interface_debug_print("ads1115: set range failed.\n");
912 (void)ads1115_deinit(&gs_handle);
913
914 return 1;
915 }
916 f_reg = (rand() % 4096) / 1000.0f;
917 ads1115_interface_debug_print("ads1115: convert to register %0.2fV.\n", f_reg);
918 res = ads1115_convert_to_register(&gs_handle, f_reg, (int16_t *)&reg);
919 if (res != 0)
920 {
921 ads1115_interface_debug_print("ads1115: convert to register failed.\n");
922 (void)ads1115_deinit(&gs_handle);
923
924 return 1;
925 }
926 ads1115_interface_debug_print("ads1115: check convert to register %s.\n", reg == (int16_t)(f_reg * 32768.0f / 4.096f) ? "ok" : "error");
927
928 /* set 2.048V */
929 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_2P048V);
930 if (res != 0)
931 {
932 ads1115_interface_debug_print("ads1115: set range failed.\n");
933 (void)ads1115_deinit(&gs_handle);
934
935 return 1;
936 }
937 f_reg = -(rand() % 2048) / 1000.0f;
938 ads1115_interface_debug_print("ads1115: convert to register %0.2fV.\n", f_reg);
939 res = ads1115_convert_to_register(&gs_handle, f_reg, (int16_t *)&reg);
940 if (res != 0)
941 {
942 ads1115_interface_debug_print("ads1115: convert to register failed.\n");
943 (void)ads1115_deinit(&gs_handle);
944
945 return 1;
946 }
947 ads1115_interface_debug_print("ads1115: check convert to register %s.\n", reg == (int16_t)(f_reg * 32768.0f / 2.048f) ? "ok" : "error");
948
949 /* set 1.024V */
950 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_1P024V);
951 if (res != 0)
952 {
953 ads1115_interface_debug_print("ads1115: set range failed.\n");
954 (void)ads1115_deinit(&gs_handle);
955
956 return 1;
957 }
958 f_reg = (rand() % 1024) / 1000.0f;
959 ads1115_interface_debug_print("ads1115: convert to register %0.2fV.\n", f_reg);
960 res = ads1115_convert_to_register(&gs_handle, f_reg, (int16_t *)&reg);
961 if (res != 0)
962 {
963 ads1115_interface_debug_print("ads1115: convert to register failed.\n");
964 (void)ads1115_deinit(&gs_handle);
965
966 return 1;
967 }
968 ads1115_interface_debug_print("ads1115: check convert to register %s.\n", reg == (int16_t)(f_reg * 32768.0f / 1.024f) ? "ok" : "error");
969
970 /* set 0.512V */
971 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_0P512V);
972 if (res != 0)
973 {
974 ads1115_interface_debug_print("ads1115: set range failed.\n");
975 (void)ads1115_deinit(&gs_handle);
976
977 return 1;
978 }
979 f_reg = -(rand() % 512) / 1000.0f;
980 ads1115_interface_debug_print("ads1115: convert to register %0.2fV.\n", f_reg);
981 res = ads1115_convert_to_register(&gs_handle, f_reg, (int16_t *)&reg);
982 if (res != 0)
983 {
984 ads1115_interface_debug_print("ads1115: convert to register failed.\n");
985 (void)ads1115_deinit(&gs_handle);
986
987 return 1;
988 }
989 ads1115_interface_debug_print("ads1115: check convert to register %s.\n", reg == (int16_t)(f_reg * 32768.0f / 0.512f) ? "ok" : "error");
990
991 /* set 0.256V */
992 res = ads1115_set_range(&gs_handle, ADS1115_RANGE_0P256V);
993 if (res != 0)
994 {
995 ads1115_interface_debug_print("ads1115: set range failed.\n");
996 (void)ads1115_deinit(&gs_handle);
997
998 return 1;
999 }
1000 f_reg = (rand() % 256) / 1000.0f;
1001 ads1115_interface_debug_print("ads1115: convert to register %0.2fV.\n", f_reg);
1002 res = ads1115_convert_to_register(&gs_handle, f_reg, (int16_t *)&reg);
1003 if (res != 0)
1004 {
1005 ads1115_interface_debug_print("ads1115: convert to register failed.\n");
1006 (void)ads1115_deinit(&gs_handle);
1007
1008 return 1;
1009 }
1010 ads1115_interface_debug_print("ads1115: check convert to register %d.\n", reg);
1011 res = ads1115_convert_to_data(&gs_handle, reg, (float *)&f_reg_check);
1012 if (res != 0)
1013 {
1014 ads1115_interface_debug_print("ads1115: convert to data failed.\n");
1015 (void)ads1115_deinit(&gs_handle);
1016
1017 return 1;
1018 }
1019 ads1115_interface_debug_print("ads1115: convert to data %0.2fV.\n", f_reg_check);
1020
1021 /* finish register */
1022 ads1115_interface_debug_print("ads1115: finish register test.\n");
1023 (void)ads1115_deinit(&gs_handle);
1024
1025 return 0;
1026}
driver ads1115 register test header file
uint8_t ads1115_get_channel(ads1115_handle_t *handle, ads1115_channel_t *channel)
get the adc channel
uint8_t ads1115_set_addr_pin(ads1115_handle_t *handle, ads1115_address_t addr_pin)
set the iic address pin
uint8_t ads1115_get_addr_pin(ads1115_handle_t *handle, ads1115_address_t *addr_pin)
get the iic address pin
ads1115_channel_t
ads1115 channel enumeration definition
uint8_t ads1115_init(ads1115_handle_t *handle)
initialize the chip
uint8_t ads1115_set_rate(ads1115_handle_t *handle, ads1115_rate_t rate)
set the sample rate
ads1115_address_t
ads1115 address enumeration definition
uint8_t ads1115_get_rate(ads1115_handle_t *handle, ads1115_rate_t *rate)
get the sample rate
uint8_t ads1115_deinit(ads1115_handle_t *handle)
close the chip
uint8_t ads1115_set_range(ads1115_handle_t *handle, ads1115_range_t range)
set the adc range
struct ads1115_info_s ads1115_info_t
ads1115 information structure definition
ads1115_rate_t
ads1115 channel rate enumeration definition
uint8_t ads1115_get_range(ads1115_handle_t *handle, ads1115_range_t *range)
get the adc range
ads1115_bool_t
ads1115 bool enumeration definition
struct ads1115_handle_s ads1115_handle_t
ads1115 handle structure definition
uint8_t ads1115_info(ads1115_info_t *info)
get chip's information
ads1115_range_t
ads1115 range enumeration definition
uint8_t ads1115_set_channel(ads1115_handle_t *handle, ads1115_channel_t channel)
set the adc channel
@ ADS1115_CHANNEL_AIN1_GND
@ ADS1115_CHANNEL_AIN1_AIN3
@ ADS1115_CHANNEL_AIN0_AIN1
@ ADS1115_CHANNEL_AIN0_GND
@ ADS1115_CHANNEL_AIN3_GND
@ ADS1115_CHANNEL_AIN2_GND
@ ADS1115_CHANNEL_AIN0_AIN3
@ ADS1115_CHANNEL_AIN2_AIN3
@ ADS1115_ADDR_VCC
@ ADS1115_ADDR_SDA
@ ADS1115_ADDR_SCL
@ ADS1115_ADDR_GND
@ ADS1115_RATE_250SPS
@ ADS1115_RATE_475SPS
@ ADS1115_RATE_860SPS
@ ADS1115_RATE_8SPS
@ ADS1115_RATE_32SPS
@ ADS1115_RATE_128SPS
@ ADS1115_RATE_64SPS
@ ADS1115_RATE_16SPS
@ ADS1115_BOOL_TRUE
@ ADS1115_BOOL_FALSE
@ ADS1115_RANGE_0P256V
@ ADS1115_RANGE_0P512V
@ ADS1115_RANGE_6P144V
@ ADS1115_RANGE_1P024V
@ ADS1115_RANGE_2P048V
@ ADS1115_RANGE_4P096V
uint8_t ads1115_interface_iic_init(void)
interface iic bus init
void ads1115_interface_delay_ms(uint32_t ms)
interface delay ms
void ads1115_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ads1115_interface_iic_deinit(void)
interface iic bus deinit
uint8_t ads1115_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t ads1115_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t ads1115_set_alert_pin(ads1115_handle_t *handle, ads1115_pin_t pin)
set the alert pin active status
uint8_t ads1115_get_alert_pin(ads1115_handle_t *handle, ads1115_pin_t *pin)
get the alert pin active status
uint8_t ads1115_set_compare(ads1115_handle_t *handle, ads1115_bool_t enable)
enable or disable the interrupt compare
uint8_t ads1115_get_comparator_queue(ads1115_handle_t *handle, ads1115_comparator_queue_t *comparator_queue)
get the interrupt comparator queue
uint8_t ads1115_convert_to_register(ads1115_handle_t *handle, float s, int16_t *reg)
convert a adc value to a register raw data
uint8_t ads1115_set_compare_threshold(ads1115_handle_t *handle, int16_t high_threshold, int16_t low_threshold)
set the interrupt compare threshold
uint8_t ads1115_set_compare_mode(ads1115_handle_t *handle, ads1115_compare_t compare)
set the interrupt compare mode
ads1115_comparator_queue_t
ads1115 comparator queue enumeration definition
uint8_t ads1115_set_comparator_queue(ads1115_handle_t *handle, ads1115_comparator_queue_t comparator_queue)
set the interrupt comparator queue
ads1115_compare_t
ads1115 compare mode enumeration definition
uint8_t ads1115_get_compare_threshold(ads1115_handle_t *handle, int16_t *high_threshold, int16_t *low_threshold)
get the interrupt compare threshold
uint8_t ads1115_get_compare_mode(ads1115_handle_t *handle, ads1115_compare_t *compare)
get the interrupt compare mode
uint8_t ads1115_get_compare(ads1115_handle_t *handle, ads1115_bool_t *enable)
get the interrupt compare status
uint8_t ads1115_convert_to_data(ads1115_handle_t *handle, int16_t reg, float *s)
convert a register raw data to a converted adc data
ads1115_pin_t
ads1115 pin enumeration definition
@ ADS1115_COMPARATOR_QUEUE_NONE_CONV
@ ADS1115_COMPARATOR_QUEUE_2_CONV
@ ADS1115_COMPARATOR_QUEUE_1_CONV
@ ADS1115_COMPARATOR_QUEUE_4_CONV
@ ADS1115_COMPARE_THRESHOLD
@ ADS1115_COMPARE_WINDOW
@ ADS1115_PIN_HIGH
@ ADS1115_PIN_LOW
uint8_t ads1115_register_test(ads1115_address_t addr)
register test
uint32_t driver_version
char manufacturer_name[32]