LibDriver ADS1118
Loading...
Searching...
No Matches
driver_ads1118_basic.c
Go to the documentation of this file.
1
36
38
39static ads1118_handle_t gs_handle;
40
51{
52 uint8_t res;
53
54 /* link interface function */
61
62 /* ads1118 init */
63 res = ads1118_init(&gs_handle);
64 if (res != 0)
65 {
66 ads1118_interface_debug_print("ads1118: init failed.\n");
67
68 return 1;
69 }
70
71 /* set channel */
72 res = ads1118_set_channel(&gs_handle, channel);
73 if (res != 0)
74 {
75 ads1118_interface_debug_print("ads1118: set channel failed.\n");
76 (void)ads1118_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set default range */
83 if (res != 0)
84 {
85 ads1118_interface_debug_print("ads1118: set range failed.\n");
86 (void)ads1118_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set default rate */
93 if (res != 0)
94 {
95 ads1118_interface_debug_print("ads1118: set rate failed.\n");
96 (void)ads1118_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set adc mode */
102 res = ads1118_set_mode(&gs_handle, mode);
103 if (res != 0)
104 {
105 ads1118_interface_debug_print("ads1118: set mode failed.\n");
106 (void)ads1118_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set default dout pull up */
113 if (res != 0)
114 {
115 ads1118_interface_debug_print("ads1118: set dout pull up failed.\n");
116 (void)ads1118_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* start continuous read */
122 res = ads1118_start_continuous_read(&gs_handle);
123 if (res != 0)
124 {
125 ads1118_interface_debug_print("ads1118: start continues read mode failed.\n");
126 (void)ads1118_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 return 0;
132}
133
142uint8_t ads1118_basic_read(float *s)
143{
144 int16_t raw;
145
146 /* read data */
147 if (ads1118_continuous_read(&gs_handle, (int16_t *)&raw, s) != 0)
148 {
149 return 1;
150 }
151
152 return 0;
153}
154
164{
165 int16_t raw;
166
167 /* read data */
168 if (ads1118_continuous_read(&gs_handle, (int16_t *)&raw, deg) != 0)
169 {
170 return 1;
171 }
172
173 /* temperature convert */
174 if (ads1118_temperature_convert(&gs_handle, raw, deg) != 0)
175 {
176 return 1;
177 }
178
179 return 0;
180}
181
190{
191 uint8_t res;
192
193 /* stop continuous read */
194 res = ads1118_stop_continuous_read(&gs_handle);
195 if (res != 0)
196 {
197 return 1;
198 }
199
200 /* deinit ads1118 */
201 res = ads1118_deinit(&gs_handle);
202 if (res != 0)
203 {
204 return 1;
205 }
206
207 return 0;
208}
driver ads1118 basic header file
uint8_t ads1118_stop_continuous_read(ads1118_handle_t *handle)
stop the chip reading
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
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
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_temperature_convert(ads1118_handle_t *handle, int16_t raw, float *deg)
temperature convert
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
#define ADS1118_BASIC_DEFAULT_RANGE
ads1118 basic example default definition
#define ADS1118_BASIC_DEFAULT_RATE
#define ADS1118_BASIC_DEFAULT_DOUT_PULL_UP
uint8_t ads1118_basic_read(float *s)
basic example read
uint8_t ads1118_basic_read_temperature(float *deg)
basic example read
uint8_t ads1118_basic_deinit(void)
basic example deinit
uint8_t ads1118_basic_init(ads1118_mode_t mode, ads1118_channel_t channel)
basic example init
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