LibDriver ADS1115
Loading...
Searching...
No Matches
driver_ads1115_interrupt.c
Go to the documentation of this file.
1
37
39
40static ads1115_handle_t gs_handle;
41
55 float f_high_threshold, float f_low_threshold)
56{
57 uint8_t res;
58 int16_t high_threshold;
59 int16_t low_threshold;
60
61 /* link interface function */
69
70 /* set addr pin */
71 res = ads1115_set_addr_pin(&gs_handle, addr);
72 if (res != 0)
73 {
74 ads1115_interface_debug_print("ads1115: set addr failed.\n");
75
76 return 1;
77 }
78
79 /* ads1115 init */
80 res = ads1115_init(&gs_handle);
81 if (res != 0)
82 {
83 ads1115_interface_debug_print("ads1115: init failed.\n");
84
85 return 1;
86 }
87
88 /* set channel */
89 res = ads1115_set_channel(&gs_handle, channel);
90 if (res != 0)
91 {
92 ads1115_interface_debug_print("ads1115: set channel failed.\n");
93 (void)ads1115_deinit(&gs_handle);
94
95 return 1;
96 }
97
98 /* set default range */
100 if (res != 0)
101 {
102 ads1115_interface_debug_print("ads1115: set range failed.\n");
103 (void)ads1115_deinit(&gs_handle);
104
105 return 1;
106 }
107
108 /* set default alert pin */
110 if (res != 0)
111 {
112 ads1115_interface_debug_print("ads1115: set alert pin failed.\n");
113 (void)ads1115_deinit(&gs_handle);
114
115 return 1;
116 }
117
118 /* set default compare mode */
119 res = ads1115_set_compare_mode(&gs_handle, compare);
120 if (res != 0)
121 {
122 ads1115_interface_debug_print("ads1115: set compare mode failed.\n");
123 (void)ads1115_deinit(&gs_handle);
124
125 return 1;
126 }
127
128 /* set default rate */
130 if (res != 0)
131 {
132 ads1115_interface_debug_print("ads1115: set rate failed.\n");
133 (void)ads1115_deinit(&gs_handle);
134
135 return 1;
136 }
137
138 /* set default comparator queue */
140 if (res != 0)
141 {
142 ads1115_interface_debug_print("ads1115: set comparator queue failed.\n");
143 (void)ads1115_deinit(&gs_handle);
144
145 return 1;
146 }
147
148 /* enable compare */
149 res = ads1115_set_compare(&gs_handle, ADS1115_BOOL_TRUE);
150 if (res != 0)
151 {
152 ads1115_interface_debug_print("ads1115: set compare failed.\n");
153 (void)ads1115_deinit(&gs_handle);
154
155 return 1;
156 }
157
158 /* convert to register */
159 res = ads1115_convert_to_register(&gs_handle, f_high_threshold, (int16_t *)&high_threshold);
160 if (res != 0)
161 {
162 ads1115_interface_debug_print("ads1115: convert to high threshold register failed.\n");
163 (void)ads1115_deinit(&gs_handle);
164
165 return 1;
166 }
167
168 /* convert to register */
169 res = ads1115_convert_to_register(&gs_handle, f_low_threshold, (int16_t *)&low_threshold);
170 if (res != 0)
171 {
172 ads1115_interface_debug_print("ads1115: convert to low threshold register failed.\n");
173 (void)ads1115_deinit(&gs_handle);
174
175 return 1;
176 }
177
178 /* set compare threshold */
179 res = ads1115_set_compare_threshold(&gs_handle, high_threshold, low_threshold);
180 if (res != 0)
181 {
182 ads1115_interface_debug_print("ads1115: set compare threshold failed.\n");
183 (void)ads1115_deinit(&gs_handle);
184
185 return 1;
186 }
187
188 /* start continuous read */
189 res = ads1115_start_continuous_read(&gs_handle);
190 if (res != 0)
191 {
192 ads1115_interface_debug_print("ads1115: start continues read mode failed.\n");
193 (void)ads1115_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 return 0;
199}
200
209uint8_t ads1115_interrupt_read(float *s)
210{
211 int16_t raw;
212
213 /* read data */
214 if (ads1115_continuous_read(&gs_handle, (int16_t *)&raw, s) != 0)
215 {
216 return 1;
217 }
218 else
219 {
220 return 0;
221 }
222}
223
232{
233 uint8_t res;
234
235 /* stop continuous read */
236 res = ads1115_stop_continuous_read(&gs_handle);
237 if (res != 0)
238 {
239 return 1;
240 }
241
242 /* deinit ads1115 */
243 res = ads1115_deinit(&gs_handle);
244 if (res != 0)
245 {
246 return 1;
247 }
248
249 return 0;
250}
driver ads1115 interrupt header file
uint8_t ads1115_set_addr_pin(ads1115_handle_t *handle, ads1115_address_t addr_pin)
set the iic address pin
uint8_t ads1115_start_continuous_read(ads1115_handle_t *handle)
start the chip reading
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_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_handle_s ads1115_handle_t
ads1115 handle structure definition
uint8_t ads1115_stop_continuous_read(ads1115_handle_t *handle)
stop the chip reading
uint8_t ads1115_set_channel(ads1115_handle_t *handle, ads1115_channel_t channel)
set the adc channel
uint8_t ads1115_continuous_read(ads1115_handle_t *handle, int16_t *raw, float *v)
read data from the chip continuously
@ ADS1115_BOOL_TRUE
uint8_t ads1115_interrupt_init(ads1115_address_t addr, ads1115_channel_t channel, ads1115_compare_t compare, float f_high_threshold, float f_low_threshold)
interrupt example init
#define ADS1115_INTERRUPT_DEFAULT_RANGE
ads1115 interrupt example default definition
#define ADS1115_INTERRUPT_DEFAULT_COMPARATOR_QUEUE
uint8_t ads1115_interrupt_read(float *s)
interrupt example read
#define ADS1115_INTERRUPT_DEFAULT_ALERT_PIN
uint8_t ads1115_interrupt_deinit(void)
interrupt example deinit
#define ADS1115_INTERRUPT_DEFAULT_RATE
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_set_compare(ads1115_handle_t *handle, ads1115_bool_t enable)
enable or disable the interrupt compare
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
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