LibDriver ADS1118
Loading...
Searching...
No Matches
driver_ads1118.c
Go to the documentation of this file.
1
36
37#include "driver_ads1118.h"
38
42#define CHIP_NAME "Texas Instruments ADS1118"
43#define MANUFACTURER_NAME "Texas Instruments"
44#define SUPPLY_VOLTAGE_MIN 2.0f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.3f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
50
54#define COMMAND_VALID (1 << 1)
55
65static uint8_t a_ads1118_spi_read(ads1118_handle_t *handle, uint16_t *data)
66{
67 uint8_t tx_buf[4];
68 uint8_t rx_buf[4];
69
70 tx_buf[0] = 0xFF; /* 0xFF */
71 tx_buf[1] = 0xFF; /* 0xFF */
72 tx_buf[2] = 0xFF; /* 0xFF */
73 tx_buf[3] = 0xFF; /* 0xFF */
74 if (handle->spi_transmit(tx_buf, rx_buf, 4) != 0) /* transmit */
75 {
76 return 1; /* return error */
77 }
78 *data = (uint16_t)((uint16_t)(rx_buf[2]) << 8) | rx_buf[3]; /* get data */
79
80 return 0; /* success return 0 */
81}
82
92static uint8_t a_ads1118_spi_read_data(ads1118_handle_t *handle, int16_t *data)
93{
94 uint8_t tx_buf[2];
95 uint8_t rx_buf[2];
96
97 tx_buf[0] = 0xFF; /* 0xFF */
98 tx_buf[1] = 0xFF; /* 0xFF */
99 if (handle->spi_transmit(tx_buf, rx_buf, 2) != 0) /* transmit */
100 {
101 return 1; /* return error */
102 }
103 *data = (int16_t)((uint16_t)(rx_buf[0]) << 8) | rx_buf[1]; /* get data */
104
105 return 0; /* success return 0 */
106}
107
117static uint8_t a_ads1118_spi_write(ads1118_handle_t *handle, uint16_t data)
118{
119 uint8_t tx_buf[2];
120 uint8_t rx_buf[2];
121
122 tx_buf[0] = (data >> 8) & 0xFF; /* set msb */
123 tx_buf[1] = (data >> 0) & 0xFF; /* set lsb */
124 if (handle->spi_transmit(tx_buf, rx_buf, 2) != 0) /* transmit */
125 {
126 return 1; /* return error */
127 }
128
129 return 0; /* success return 0 */
130}
131
143{
144 if (handle == NULL) /* check handle */
145 {
146 return 2; /* return error */
147 }
148 if (handle->debug_print == NULL) /* check debug_print */
149 {
150 return 3; /* return error */
151 }
152 if (handle->spi_init == NULL) /* check spi_init */
153 {
154 handle->debug_print("ads1118: spi_init is null.\n"); /* spi_init is null */
155
156 return 3; /* return error */
157 }
158 if (handle->spi_deinit == NULL) /* check spi_deinit */
159 {
160 handle->debug_print("ads1118: spi_deinit is null.\n"); /* spi_deinit is null */
161
162 return 3; /* return error */
163 }
164 if (handle->spi_transmit == NULL) /* check spi_transmit */
165 {
166 handle->debug_print("ads1118: spi_transmit is null.\n"); /* spi_transmit is null */
167
168 return 3; /* return error */
169 }
170 if (handle->delay_ms == NULL) /* check delay_ms */
171 {
172 handle->debug_print("ads1118: delay_ms is null.\n"); /* delay_ms is null */
173
174 return 3; /* return error */
175 }
176
177 if (handle->spi_init() != 0) /* spi init */
178 {
179 handle->debug_print("ads1118: spi init failed.\n"); /* spi init failed */
180
181 return 1; /* return error */
182 }
183 handle->inited = 1; /* flag inited */
184
185 return 0; /* success return 0 */
186}
187
200{
201 uint8_t res;
202 uint16_t conf;
203
204 if (handle == NULL) /* check handle */
205 {
206 return 2; /* return error */
207 }
208 if (handle->inited != 1) /* check handle initialization */
209 {
210 return 3; /* return error */
211 }
212
213 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
214 if (res != 0) /* check error */
215 {
216 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
217
218 return 4; /* return error */
219 }
220 conf &= ~(0x01 << 8); /* clear bit */
221 conf |= 1 << 8; /* set stop continues read */
222 res = a_ads1118_spi_write(handle, conf); /* write config */
223 if (res != 0) /* check error */
224 {
225 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
226
227 return 4; /* return error */
228 }
229 res = handle->spi_deinit(); /* close spi */
230 if (res != 0) /* check the result */
231 {
232 handle->debug_print("ads1118: spi deinit failed.\n"); /* spi deinit failed */
233
234 return 1; /* return error */
235 }
236 handle->inited = 0; /* flag close */
237
238 return 0; /* success return 0 */
239}
240
253{
254 uint8_t res;
255 uint16_t conf;
256
257 if (handle == NULL) /* check handle */
258 {
259 return 2; /* return error */
260 }
261 if (handle->inited != 1) /* check handle initialization */
262 {
263 return 3; /* return error */
264 }
265
266 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
267 if (res != 0) /* check error */
268 {
269 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
270
271 return 1; /* return error */
272 }
273 conf &= ~(0x07 << 12); /* clear channel */
274 conf |= (channel & 0x07) << 12; /* set channel */
275 conf &= ~(3 << 1); /* clear nop */
276 conf |= COMMAND_VALID; /* set command valid */
277 res = a_ads1118_spi_write(handle, conf); /* write config */
278 if (res != 0) /* check error */
279 {
280 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
281
282 return 1; /* return error */
283 }
284
285 return 0; /* success return 0 */
286}
287
300{
301 uint8_t res;
302 uint16_t conf;
303
304 if (handle == NULL) /* check handle */
305 {
306 return 2; /* return error */
307 }
308 if (handle->inited != 1) /* check handle initialization */
309 {
310 return 3; /* return error */
311 }
312
313 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
314 if (res != 0) /* check error */
315 {
316 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
317
318 return 1; /* return error */
319 }
320 *channel = (ads1118_channel_t)((conf >> 12) & 0x07); /* get channel */
321
322 return 0; /* success return 0 */
323}
324
337{
338 uint8_t res;
339 uint16_t conf;
340
341 if (handle == NULL) /* check handle */
342 {
343 return 2; /* return error */
344 }
345 if (handle->inited != 1) /* check handle initialization */
346 {
347 return 3; /* return error */
348 }
349
350 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
351 if (res != 0) /* check error */
352 {
353 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
354
355 return 1; /* return error */
356 }
357 conf &= ~(0x07 << 9); /* clear range */
358 conf |= (range & 0x07) << 9; /* set range */
359 conf &= ~(3 << 1); /* clear nop */
360 conf |= COMMAND_VALID; /* set command valid */
361 res = a_ads1118_spi_write(handle, conf); /* write config */
362 if (res != 0) /* check error */
363 {
364 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
365
366 return 1; /* return error */
367 }
368
369 return 0; /* success return 0 */
370}
371
384{
385 uint8_t res;
386 uint16_t conf;
387
388 if (handle == NULL) /* check handle */
389 {
390 return 2; /* return error */
391 }
392 if (handle->inited != 1) /* check handle initialization */
393 {
394 return 3; /* return error */
395 }
396
397 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
398 if (res != 0) /* check error */
399 {
400 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
401
402 return 1; /* return error */
403 }
404 *range = (ads1118_range_t)((conf >> 9) & 0x07); /* get range */
405
406 return 0; /* success return 0 */
407}
408
421{
422 uint8_t res;
423 uint16_t conf;
424
425 if (handle == NULL) /* check handle */
426 {
427 return 2; /* return error */
428 }
429 if (handle->inited != 1) /* check handle initialization */
430 {
431 return 3; /* return error */
432 }
433
434 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
435 if (res != 0) /* check error */
436 {
437 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
438
439 return 1; /* return error */
440 }
441 conf &= ~(0x07 << 5); /* clear rate */
442 conf |= (rate & 0x07) << 5; /* set rate */
443 conf &= ~(3 << 1); /* clear nop */
444 conf |= COMMAND_VALID; /* set command valid */
445 res = a_ads1118_spi_write(handle, conf); /* write config */
446 if (res != 0) /* check error */
447 {
448 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
449
450 return 1; /* return error */
451 }
452
453 return 0; /* success return */
454}
455
468{
469 uint8_t res;
470 uint16_t conf;
471
472 if (handle == NULL) /* check handle */
473 {
474 return 2; /* return error */
475 }
476 if (handle->inited != 1) /* check handle initialization */
477 {
478 return 3; /* return error */
479 }
480
481 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
482 if (res != 0) /* check error */
483 {
484 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
485
486 return 1; /* return error */
487 }
488 *rate = (ads1118_rate_t)((conf >> 5) & 0x07); /* get rate */
489
490 return 0; /* success return 0 */
491}
492
505{
506 uint8_t res;
507 uint16_t conf;
508
509 if (handle == NULL) /* check handle */
510 {
511 return 2; /* return error */
512 }
513 if (handle->inited != 1) /* check handle initialization */
514 {
515 return 3; /* return error */
516 }
517
518 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
519 if (res != 0) /* check error */
520 {
521 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
522
523 return 1; /* return error */
524 }
525 conf &= ~(1 << 4); /* clear settings */
526 conf |= mode << 4; /* set mode */
527 conf &= ~(3 << 1); /* clear nop */
528 conf |= COMMAND_VALID; /* set command valid */
529 res = a_ads1118_spi_write(handle, conf); /* write config */
530 if (res != 0) /* check error */
531 {
532 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
533
534 return 1; /* return error */
535 }
536
537 return 0; /* success return */
538}
539
552{
553 uint8_t res;
554 uint16_t conf;
555
556 if (handle == NULL) /* check handle */
557 {
558 return 2; /* return error */
559 }
560 if (handle->inited != 1) /* check handle initialization */
561 {
562 return 3; /* return error */
563 }
564
565 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
566 if (res != 0) /* check error */
567 {
568 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
569
570 return 1; /* return error */
571 }
572 *mode = (ads1118_mode_t)((conf >> 4) & 0x01); /* get mode */
573
574 return 0; /* success return 0 */
575}
576
589{
590 uint8_t res;
591 uint16_t conf;
592
593 if (handle == NULL) /* check handle */
594 {
595 return 2; /* return error */
596 }
597 if (handle->inited != 1) /* check handle initialization */
598 {
599 return 3; /* return error */
600 }
601
602 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
603 if (res != 0) /* check error */
604 {
605 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
606
607 return 1; /* return error */
608 }
609 conf &= ~(1 << 3); /* clear settings */
610 conf |= enable << 3; /* set enable */
611 conf &= ~(3 << 1); /* clear nop */
612 conf |= COMMAND_VALID; /* set command valid */
613 res = a_ads1118_spi_write(handle, conf); /* write config */
614 if (res != 0) /* check error */
615 {
616 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
617
618 return 1; /* return error */
619 }
620
621 return 0; /* success return */
622}
623
636{
637 uint8_t res;
638 uint16_t conf;
639
640 if (handle == NULL) /* check handle */
641 {
642 return 2; /* return error */
643 }
644 if (handle->inited != 1) /* check handle initialization */
645 {
646 return 3; /* return error */
647 }
648
649 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
650 if (res != 0) /* check error */
651 {
652 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
653
654 return 1; /* return error */
655 }
656 *enable = (ads1118_bool_t)((conf >> 3) & 0x01); /* get bool */
657
658 return 0; /* success return */
659}
660
673uint8_t ads1118_single_read(ads1118_handle_t *handle, int16_t *raw, float *v)
674{
675 uint8_t res;
676 uint8_t range;
677 uint8_t rate;
678 uint16_t conf;
679
680 if (handle == NULL) /* check handle */
681 {
682 return 2; /* return error */
683 }
684 if (handle->inited != 1) /* check handle initialization */
685 {
686 return 3; /* return error */
687 }
688
689 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
690 if (res != 0) /* check error */
691 {
692 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
693
694 return 1; /* return error */
695 }
696 range = (ads1118_range_t)((conf >> 9) & 0x07); /* get range conf */
697 conf &= ~(1 << 8); /* clear bit */
698 conf |= 1 << 8; /* set single read */
699 conf |= 1 << 15; /* start single read */
700 res = a_ads1118_spi_write(handle, conf); /* write config */
701 if (res != 0) /* check error */
702 {
703 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
704
705 return 1; /* return error */
706 }
707 rate = (conf >> 5) & 0x7; /* set rate */
708 switch (rate) /* choose the rate */
709 {
710 case 0 : /* 8sps */
711 {
712 handle->delay_ms(138); /* > ((1000 / 8) *(1 + 10%)) */
713
714 break; /* break */
715 }
716 case 1 : /* 16sps */
717 {
718 handle->delay_ms(69); /* > ((1000 / 16) *(1 + 10%)) */
719
720 break; /* break */
721 }
722 case 2 : /* 32sps */
723 {
724 handle->delay_ms(35); /* > ((1000 / 32) *(1 + 10%)) */
725
726 break; /* break */
727 }
728 case 3 : /* 64sps */
729 {
730 handle->delay_ms(18); /* > ((1000 / 64) *(1 + 10%)) */
731
732 break; /* break */
733 }
734 case 4 : /* 128sps */
735 {
736 handle->delay_ms(9); /* > ((1000 / 128) *(1 + 10%)) */
737
738 break; /* break */
739 }
740 case 5 : /* 250sps */
741 {
742 handle->delay_ms(5); /* > ((1000 / 250) *(1 + 10%)) */
743
744 break; /* break */
745 }
746 case 6 : /* 475sps */
747 {
748 handle->delay_ms(3); /* > ((1000 / 475) *(1 + 10%)) */
749
750 break; /* break */
751 }
752 case 7 : /* 860sps */
753 {
754 handle->delay_ms(2); /* > ((1000 / 860) *(1 + 10%)) */
755
756 break; /* break */
757 }
758 default :
759 {
760 handle->delay_ms(200); /* 200ms */
761
762 break; /* break */
763 }
764 }
765 res = a_ads1118_spi_read_data(handle, raw); /* read data */
766 if (res != 0) /* check the result */
767 {
768 handle->debug_print("ads1118: continues read failed.\n"); /* continues read failed */
769
770 return 1; /* return error */
771 }
772 if (range == ADS1118_RANGE_6P144V) /* if 6.144V */
773 {
774 *v = (float)(*raw) * 6.144f / 32768.0f; /* get convert adc */
775 }
776 else if (range == ADS1118_RANGE_4P096V) /* if 4.096V */
777 {
778 *v = (float)(*raw) * 4.096f / 32768.0f; /* get convert adc */
779 }
780 else if (range == ADS1118_RANGE_2P048V) /* if 2.048V */
781 {
782 *v = (float)(*raw) * 2.048f / 32768.0f; /* get convert adc */
783 }
784 else if (range == ADS1118_RANGE_1P024V) /* if 1.024V */
785 {
786 *v = (float)(*raw) * 1.024f / 32768.0f; /* get convert adc */
787 }
788 else if (range == ADS1118_RANGE_0P512V) /* if 0.512V */
789 {
790 *v = (float)(*raw) * 0.512f / 32768.0f; /* get convert adc */
791 }
792 else if (range == ADS1118_RANGE_0P256V) /* if 0.256V */
793 {
794 *v = (float)(*raw) * 0.256f / 32768.0f; /* get convert adc */
795 }
796 else
797 {
798 handle->debug_print("ads1118: range is invalid.\n"); /* range is invalid */
799
800 return 1; /* return error */
801 }
802
803 return 0; /* success return 0 */
804}
805
819uint8_t ads1118_continuous_read(ads1118_handle_t *handle, int16_t *raw, float *v)
820{
821 uint8_t res;
822 uint8_t range;
823 uint16_t conf;
824
825 if (handle == NULL) /* check handle */
826 {
827 return 2; /* return error */
828 }
829 if (handle->inited != 1) /* check handle initialization */
830 {
831 return 3; /* return error */
832 }
833
834 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
835 if (res != 0) /* check error */
836 {
837 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
838
839 return 1; /* return error */
840 }
841 range = (ads1118_range_t)((conf >> 9) & 0x07); /* get range conf */
842 res = a_ads1118_spi_read_data(handle, raw); /* read data */
843 if (res != 0) /* check error */
844 {
845 handle->debug_print("ads1118: continuous read failed.\n"); /* continuous read failed */
846
847 return 1; /* return error */
848 }
849 if (range == ADS1118_RANGE_6P144V) /* if 6.144V */
850 {
851 *v = (float)(*raw) * 6.144f / 32768.0f; /* get convert adc */
852 }
853 else if (range == ADS1118_RANGE_4P096V) /* if 4.096V */
854 {
855 *v = (float)(*raw) * 4.096f / 32768.0f; /* get convert adc */
856 }
857 else if (range == ADS1118_RANGE_2P048V) /* if 2.048V */
858 {
859 *v = (float)(*raw) * 2.048f / 32768.0f; /* get convert adc */
860 }
861 else if (range == ADS1118_RANGE_1P024V) /* if 1.024V */
862 {
863 *v = (float)(*raw) * 1.024f / 32768.0f; /* get convert adc */
864 }
865 else if (range == ADS1118_RANGE_0P512V) /* if 0.512V */
866 {
867 *v = (float)(*raw) * 0.512f / 32768.0f; /* get convert adc */
868 }
869 else if (range == ADS1118_RANGE_0P256V) /* if 0.256V */
870 {
871 *v = (float)(*raw) * 0.256f / 32768.0f; /* get convert adc */
872 }
873 else
874 {
875 handle->debug_print("ads1118: range is invalid.\n"); /* range is invalid */
876
877 return 1; /* return error */
878 }
879
880 return 0; /* success return 0 */
881}
882
894{
895 uint8_t res;
896 uint16_t conf;
897
898 if (handle == NULL) /* check handle */
899 {
900 return 2; /* return error */
901 }
902 if (handle->inited != 1) /* check handle initialization */
903 {
904 return 3; /* return error */
905 }
906
907 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
908 if (res != 0) /* check error */
909 {
910 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
911
912 return 1; /* return error */
913 }
914 conf &= ~(0x01 << 8); /* set start continuous read */
915 res = a_ads1118_spi_write(handle, conf); /* write config */
916 if (res != 0) /* check error */
917 {
918 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
919
920 return 1; /* return error */
921 }
922
923 return 0; /* success return 0 */
924}
925
937{
938 uint8_t res;
939 uint16_t conf;
940
941 if (handle == NULL) /* check handle */
942 {
943 return 2; /* return error */
944 }
945 if (handle->inited != 1) /* check handle initialization */
946 {
947 return 3; /* return error */
948 }
949
950 res = a_ads1118_spi_read(handle, (uint16_t *)&conf); /* read config */
951 if (res != 0) /* check error */
952 {
953 handle->debug_print("ads1118: read config failed.\n"); /* read config failed */
954
955 return 1; /* return error */
956 }
957 conf &= ~(0x01 << 8); /* clear bit */
958 conf |= 1 << 8; /* set stop continues read */
959 res = a_ads1118_spi_write(handle, conf); /* write config */
960 if (res != 0) /* check error */
961 {
962 handle->debug_print("ads1118: write config failed.\n"); /* write config failed */
963
964 return 1; /* return error */
965 }
966
967 return 0; /* success return 0 */
968}
969
981uint8_t ads1118_temperature_convert(ads1118_handle_t *handle, int16_t raw, float *deg)
982{
983 if (handle == NULL) /* check handle */
984 {
985 return 2; /* return error */
986 }
987 if (handle->inited != 1) /* check handle initialization */
988 {
989 return 3; /* return error */
990 }
991
992 *deg = (float)(raw) * 0.03125f / 4.0f; /* convert to deg */
993
994 return 0; /* success return 0 */
995}
996
1010uint8_t ads1118_transmit(ads1118_handle_t *handle, uint8_t *tx, uint8_t *rx, uint16_t len)
1011{
1012 if (handle == NULL) /* check handle */
1013 {
1014 return 2; /* return error */
1015 }
1016 if (handle->inited != 1) /* check handle initialization */
1017 {
1018 return 3; /* return error */
1019 }
1020
1021 if (handle->spi_transmit(tx, rx, len) != 0) /* spi transmit */
1022 {
1023 return 1; /* return error */
1024 }
1025
1026 return 0; /* success return 0 */
1027}
1028
1038{
1039 if (info == NULL) /* check handle */
1040 {
1041 return 2; /* return error */
1042 }
1043
1044 memset(info, 0, sizeof(ads1118_info_t)); /* initialize ads1118 info structure */
1045 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1046 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1047 strncpy(info->interface, "SPI", 8); /* copy interface name */
1048 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1049 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1050 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1051 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1052 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1053 info->driver_version = DRIVER_VERSION; /* set driver version */
1054
1055 return 0; /* success return 0 */
1056}
#define MAX_CURRENT
#define COMMAND_VALID
command definition
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver ads1118 header file
uint8_t ads1118_stop_continuous_read(ads1118_handle_t *handle)
stop the chip reading
uint8_t ads1118_single_read(ads1118_handle_t *handle, int16_t *raw, float *v)
read data from the chip once
uint8_t ads1118_get_channel(ads1118_handle_t *handle, ads1118_channel_t *channel)
get the adc channel
uint8_t ads1118_set_channel(ads1118_handle_t *handle, ads1118_channel_t channel)
set the adc channel
uint8_t ads1118_set_range(ads1118_handle_t *handle, ads1118_range_t range)
set the adc range
uint8_t ads1118_info(ads1118_info_t *info)
get chip's information
ads1118_mode_t
ads1118 mode enumeration definition
uint8_t ads1118_continuous_read(ads1118_handle_t *handle, int16_t *raw, float *v)
read data from the chip continuously
ads1118_bool_t
ads1118 bool enumeration definition
uint8_t ads1118_get_mode(ads1118_handle_t *handle, ads1118_mode_t *mode)
get the chip mode
struct ads1118_info_s ads1118_info_t
ads1118 information structure definition
ads1118_range_t
ads1118 range enumeration definition
uint8_t ads1118_init(ads1118_handle_t *handle)
initialize the chip
uint8_t ads1118_set_dout_pull_up(ads1118_handle_t *handle, ads1118_bool_t enable)
enable or disable dout pull up
uint8_t ads1118_deinit(ads1118_handle_t *handle)
close the chip
struct ads1118_handle_s ads1118_handle_t
ads1118 handle structure definition
uint8_t ads1118_set_rate(ads1118_handle_t *handle, ads1118_rate_t rate)
set the sample rate
uint8_t ads1118_get_rate(ads1118_handle_t *handle, ads1118_rate_t *rate)
get the sample rate
ads1118_channel_t
ads1118 channel enumeration definition
uint8_t ads1118_temperature_convert(ads1118_handle_t *handle, int16_t raw, float *deg)
temperature convert
ads1118_rate_t
ads1118 channel rate enumeration definition
uint8_t ads1118_start_continuous_read(ads1118_handle_t *handle)
start the chip reading
uint8_t ads1118_set_mode(ads1118_handle_t *handle, ads1118_mode_t mode)
set the chip mode
uint8_t ads1118_get_dout_pull_up(ads1118_handle_t *handle, ads1118_bool_t *enable)
get dout pull up status
uint8_t ads1118_get_range(ads1118_handle_t *handle, ads1118_range_t *range)
get the adc range
@ ADS1118_RANGE_0P256V
@ ADS1118_RANGE_1P024V
@ ADS1118_RANGE_0P512V
@ ADS1118_RANGE_2P048V
@ ADS1118_RANGE_6P144V
@ ADS1118_RANGE_4P096V
uint8_t ads1118_transmit(ads1118_handle_t *handle, uint8_t *tx, uint8_t *rx, uint16_t len)
chip transmit
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_transmit)(uint8_t *tx, uint8_t *rx, uint16_t len)
uint8_t(* spi_deinit)(void)
uint32_t driver_version
char manufacturer_name[32]