LibDriver AD7705
Loading...
Searching...
No Matches
driver_ad7705_basic.c
Go to the documentation of this file.
1
36
37#include "driver_ad7705_basic.h"
38
39static ad7705_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link functions */
64
65 /* ad7705 init */
66 res = ad7705_init(&gs_handle);
67 if (res != 0)
68 {
69 ad7705_interface_debug_print("ad7705: init failed.\n");
70
71 return 1;
72 }
73
74 /* power on */
75 res = ad7705_power_on(&gs_handle);
76 if (res != 0)
77 {
78 ad7705_interface_debug_print("ad7705: power on failed.\n");
79 (void)ad7705_deinit(&gs_handle);
80
81 return 1;
82 }
83
84 /* set default reference voltage */
86 if (res != 0)
87 {
88 ad7705_interface_debug_print("ad7705: reference voltage failed.\n");
89 (void)ad7705_deinit(&gs_handle);
90
91 return 1;
92 }
93
94 /* set channel */
95 res = ad7705_set_channel(&gs_handle, channel);
96 if (res != 0)
97 {
98 ad7705_interface_debug_print("ad7705: set channel failed.\n");
99 (void)ad7705_deinit(&gs_handle);
100
101 return 1;
102 }
103
104 /* set default adc gain */
106 if (res != 0)
107 {
108 ad7705_interface_debug_print("ad7705: set adc gain failed.\n");
109 (void)ad7705_deinit(&gs_handle);
110
111 return 1;
112 }
113
114 /* set default adc buffer */
116 if (res != 0)
117 {
118 ad7705_interface_debug_print("ad7705: set adc buffer failed.\n");
119 (void)ad7705_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* set default filter synchronize */
126 if (res != 0)
127 {
128 ad7705_interface_debug_print("ad7705: set filter synchronize failed.\n");
129 (void)ad7705_deinit(&gs_handle);
130
131 return 1;
132 }
133
134 /* set default master clock output disable */
136 if (res != 0)
137 {
138 ad7705_interface_debug_print("ad7705: set master clock output disable failed.\n");
139 (void)ad7705_deinit(&gs_handle);
140
141 return 1;
142 }
143
144 /* set default clock div2 */
146 if (res != 0)
147 {
148 ad7705_interface_debug_print("ad7705: set clock div2 failed.\n");
149 (void)ad7705_deinit(&gs_handle);
150
151 return 1;
152 }
153
154 /* set default rate */
156 if (res != 0)
157 {
158 ad7705_interface_debug_print("ad7705: set rate failed.\n");
159 (void)ad7705_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* set default adc polar */
166 if (res != 0)
167 {
168 ad7705_interface_debug_print("ad7705: set adc polar failed.\n");
169 (void)ad7705_deinit(&gs_handle);
170
171 return 1;
172 }
173
174 /* run self calibration */
176 if (res != 0)
177 {
178 ad7705_interface_debug_print("ad7705: set adc mode failed.\n");
179 (void)ad7705_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* wait for finishing */
185 res = ad7705_operate_sync(&gs_handle);
186 if (res != 0)
187 {
188 ad7705_interface_debug_print("ad7705: operate sync failed.\n");
189 (void)ad7705_deinit(&gs_handle);
190
191 return 1;
192 }
193
194 return 0;
195}
196
206{
207 uint8_t res;
208
209 /* set channel */
210 res = ad7705_set_channel(&gs_handle, channel);
211 if (res != 0)
212 {
213 return 1;
214 }
215
216 return 0;
217}
218
227{
228 /* close ad7705 */
229 if (ad7705_deinit(&gs_handle) != 0)
230 {
231 return 1;
232 }
233
234 return 0;
235}
236
246uint8_t ad7705_basic_read(uint16_t *raw, float *volt)
247{
248 /* read data */
249 if (ad7705_read(&gs_handle, raw, volt) != 0)
250 {
251 return 1;
252 }
253
254 return 0;
255}
driver ad7705 basic include file
uint8_t ad7705_set_master_clock_output_disable(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable master clock output disable
ad7705_channel_t
ad7705 channel enumeration definition
struct ad7705_handle_s ad7705_handle_t
ad7705 handle structure definition
uint8_t ad7705_init(ad7705_handle_t *handle)
initialize the chip
uint8_t ad7705_set_adc_buffer(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable adc buffer
uint8_t ad7705_set_reference_voltage(ad7705_handle_t *handle, float voltage)
set reference voltage
uint8_t ad7705_operate_sync(ad7705_handle_t *handle)
operate sync
uint8_t ad7705_deinit(ad7705_handle_t *handle)
close the chip
uint8_t ad7705_set_adc_gain(ad7705_handle_t *handle, ad7705_adc_gain_t gain)
set adc gain
uint8_t ad7705_set_rate(ad7705_handle_t *handle, ad7705_rate_t rate)
set rate
uint8_t ad7705_read(ad7705_handle_t *handle, uint16_t *raw, float *volt)
read adc
uint8_t ad7705_set_clock_div2(ad7705_handle_t *handle, ad7705_bool_t enable)
enable or disable clock div2
uint8_t ad7705_set_adc_mode(ad7705_handle_t *handle, ad7705_adc_mode_t mode)
set adc mode
uint8_t ad7705_power_on(ad7705_handle_t *handle)
power on
uint8_t ad7705_set_channel(ad7705_handle_t *handle, ad7705_channel_t channel)
set channel
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_ADC_MODE_SELF_CALIBRATION
#define AD7705_BASIC_DEFAULT_RATE
#define AD7705_BASIC_DEFAULT_ADC_BUFFER
#define AD7705_BASIC_DEFAULT_CLOCK_DIV2
uint8_t ad7705_basic_set_channel(ad7705_channel_t channel)
basic example set channel
#define AD7705_BASIC_DEFAULT_GAIN
uint8_t ad7705_basic_deinit(void)
basic example deinit
uint8_t ad7705_basic_init(ad7705_channel_t channel)
basic example init
#define AD7705_BASIC_DEFAULT_REFERENCE_VOLTAGE
ad7705 basic example default definition
uint8_t ad7705_basic_read(uint16_t *raw, float *volt)
basic example read adc
#define AD7705_BASIC_DEFAULT_ADC_POLAR
#define AD7705_BASIC_DEFAULT_MASTER_CLOCK_OUTPUT_DISABLE
#define AD7705_BASIC_DEFAULT_FILTER_SYNCHRONIZE
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