LibDriver ADS1118
Loading...
Searching...
No Matches
driver_ads1118_mutichannel_test.c
Go to the documentation of this file.
1
36
38
39static ads1118_handle_t gs_handle;
40
50uint8_t ads1118_multichannel_test(ads1118_channel_t channel, uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 ads1118_info_t info;
55
56 /* link interface function */
63
64 /* get information */
65 res = ads1118_info(&info);
66 if (res != 0)
67 {
68 ads1118_interface_debug_print("ads1118: get info failed.\n");
69
70 return 1;
71 }
72 else
73 {
74 /* print chip info */
75 ads1118_interface_debug_print("ads1118: chip is %s.\n", info.chip_name);
76 ads1118_interface_debug_print("ads1118: manufacturer is %s.\n", info.manufacturer_name);
77 ads1118_interface_debug_print("ads1118: interface is %s.\n", info.interface);
78 ads1118_interface_debug_print("ads1118: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
79 ads1118_interface_debug_print("ads1118: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
80 ads1118_interface_debug_print("ads1118: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
81 ads1118_interface_debug_print("ads1118: max current is %0.2fmA.\n", info.max_current_ma);
82 ads1118_interface_debug_print("ads1118: max temperature is %0.1fC.\n", info.temperature_max);
83 ads1118_interface_debug_print("ads1118: min temperature is %0.1fC.\n", info.temperature_min);
84 }
85
86 /* ads1118 init */
87 res = ads1118_init(&gs_handle);
88 if (res != 0)
89 {
90 ads1118_interface_debug_print("ads1118: init failed.\n");
91
92 return 1;
93 }
94
95 /* set range 6.144V */
96 res = ads1118_set_range(&gs_handle, ADS1118_RANGE_6P144V);
97 if (res != 0)
98 {
99 ads1118_interface_debug_print("ads1118: set range failed.\n");
100 (void)ads1118_deinit(&gs_handle);
101
102 return 1;
103 }
104
105 /* set 128SPS rate */
106 res = ads1118_set_rate(&gs_handle, ADS1118_RATE_128SPS);
107 if (res != 0)
108 {
109 ads1118_interface_debug_print("ads1118: set rate failed.\n");
110 (void)ads1118_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* disable dout pull up */
117 if (res != 0)
118 {
119 ads1118_interface_debug_print("ads1118: set dout pull up failed.\n");
120 (void)ads1118_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* set adc mode */
126 res = ads1118_set_mode(&gs_handle, ADS1118_MODE_ADC);
127 if (res != 0)
128 {
129 ads1118_interface_debug_print("ads1118: set mode failed.\n");
130 (void)ads1118_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* start multichannel test */
136 ads1118_interface_debug_print("ads1118: start multichannel test.\n");
137 res = ads1118_set_channel(&gs_handle, channel);
138 if (res != 0)
139 {
140 ads1118_interface_debug_print("ads1118: set channel failed.\n");
141 (void)ads1118_deinit(&gs_handle);
142
143 return 1;
144 }
145 for (i = 0; i < times; i++)
146 {
147 int16_t raw;
148 float s;
149
150 /* single read */
151 res = ads1118_single_read(&gs_handle, (int16_t *)&raw, (float *)&s);
152 if (res != 0)
153 {
154 ads1118_interface_debug_print("ads1118: read failed.\n");
155 (void)ads1118_deinit(&gs_handle);
156
157 return 1;
158 }
159 ads1118_interface_debug_print("ads1118: %d/%d voltage is %0.2fV.\n", i + 1, times, s);
161 }
162
163 /* finish multichannel test */
164 ads1118_interface_debug_print("ads1118: finish multichannel test.\n");
165 (void)ads1118_deinit(&gs_handle);
166
167 return 0;
168}
driver ads1118 mutichannel test header file
uint8_t ads1118_single_read(ads1118_handle_t *handle, int16_t *raw, float *v)
read data from the chip once
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
struct ads1118_info_s ads1118_info_t
ads1118 information structure 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
ads1118_channel_t
ads1118 channel enumeration definition
uint8_t ads1118_set_mode(ads1118_handle_t *handle, ads1118_mode_t mode)
set the chip mode
@ ADS1118_MODE_ADC
@ ADS1118_BOOL_FALSE
@ ADS1118_RANGE_6P144V
@ ADS1118_RATE_128SPS
void ads1118_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ads1118_interface_spi_transmit(uint8_t *tx, uint8_t *rx, uint16_t len)
interface spi bus transmit
uint8_t ads1118_interface_spi_deinit(void)
interface spi bus deinit
uint8_t ads1118_interface_spi_init(void)
interface spi bus init
void ads1118_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ads1118_multichannel_test(ads1118_channel_t channel, uint32_t times)
multichannel test
uint32_t driver_version
char manufacturer_name[32]