LibDriver ADS1115
Loading...
Searching...
No Matches
driver_ads1115_basic.c
Go to the documentation of this file.
1
37
39
40static ads1115_handle_t gs_handle;
41
52{
53 uint8_t res;
54
55 /* link interface function */
63
64 /* set addr pin */
65 res = ads1115_set_addr_pin(&gs_handle, addr);
66 if (res != 0)
67 {
68 ads1115_interface_debug_print("ads1115: set addr failed.\n");
69
70 return 1;
71 }
72
73 /* ads1115 init */
74 res = ads1115_init(&gs_handle);
75 if (res != 0)
76 {
77 ads1115_interface_debug_print("ads1115: init failed.\n");
78
79 return 1;
80 }
81
82 /* set channel */
83 res = ads1115_set_channel(&gs_handle, channel);
84 if (res != 0)
85 {
86 ads1115_interface_debug_print("ads1115: set channel failed.\n");
87 (void)ads1115_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* set default range */
94 if (res != 0)
95 {
96 ads1115_interface_debug_print("ads1115: set range failed.\n");
97 (void)ads1115_deinit(&gs_handle);
98
99 return 1;
100 }
101
102 /* set default rate */
104 if (res != 0)
105 {
106 ads1115_interface_debug_print("ads1115: set rate failed.\n");
107 (void)ads1115_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* disable compare */
113 res = ads1115_set_compare(&gs_handle, ADS1115_BOOL_FALSE);
114 if (res != 0)
115 {
116 ads1115_interface_debug_print("ads1115: set compare failed.\n");
117 (void)ads1115_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* start continuous read */
123 res = ads1115_start_continuous_read(&gs_handle);
124 if (res != 0)
125 {
126 ads1115_interface_debug_print("ads1115: start continuous read mode failed.\n");
127 (void)ads1115_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 return 0;
133}
134
143uint8_t ads1115_basic_read(float *s)
144{
145 int16_t raw;
146
147 /* read data */
148 if (ads1115_continuous_read(&gs_handle, (int16_t *)&raw, s) != 0)
149 {
150 return 1;
151 }
152 else
153 {
154 return 0;
155 }
156}
157
166{
167 uint8_t res;
168
169 /* stop continuous read */
170 res = ads1115_stop_continuous_read(&gs_handle);
171 if (res != 0)
172 {
173 return 1;
174 }
175
176 /* deinit ads1115 */
177 res = ads1115_deinit(&gs_handle);
178 if (res != 0)
179 {
180 return 1;
181 }
182
183 return 0;
184}
driver ads1115 basic 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_FALSE
uint8_t ads1115_basic_init(ads1115_address_t addr, ads1115_channel_t channel)
basic example init
uint8_t ads1115_basic_read(float *s)
basic example read
uint8_t ads1115_basic_deinit(void)
basic example deinit
#define ADS1115_BASIC_DEFAULT_RANGE
ads1115 basic example default definition
#define ADS1115_BASIC_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_compare(ads1115_handle_t *handle, ads1115_bool_t enable)
enable or disable the interrupt compare