adc24 2.1.0.0
adc24.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef ADC24_H
29#define ADC24_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define ADC24_CTRL_SET_WRITE 0x0800u
75#define ADC24_CTRL_SET_SEQ 0x0400u
76#define ADC24_CTRL_SET_CH_0 0x0000u
77#define ADC24_CTRL_SET_CH_1 0x0040u
78#define ADC24_CTRL_SET_CH_2 0x0080u
79#define ADC24_CTRL_SET_CH_3 0x00C0u
80#define ADC24_CTRL_SET_CH_4 0x0100u
81#define ADC24_CTRL_SET_CH_5 0x0140u
82#define ADC24_CTRL_SET_CH_6 0x0180u
83#define ADC24_CTRL_SET_CH_7 0x01C0u
84#define ADC24_CTRL_SET_CH_8 0x0200u
85#define ADC24_CTRL_SET_CH_9 0x0240u
86#define ADC24_CTRL_SET_CH_10 0x0280u
87#define ADC24_CTRL_SET_CH_11 0x02C0u
88#define ADC24_CTRL_SET_CH_12 0x0300u
89#define ADC24_CTRL_SET_CH_13 0x0340u
90#define ADC24_CTRL_SET_CH_14 0x0380u
91#define ADC24_CTRL_SET_CH_15 0x03C0u
92#define ADC24_CTRL_SET_PM_NORMAL 0x0030u
93#define ADC24_CTRL_SET_PM_FULL_SHDN 0x0020u
94#define ADC24_CTRL_SET_PM_AUTO_SHDN 0x0010u
95#define ADC24_CTRL_SET_PM_STANDBY 0x0000u
96#define ADC24_CTRL_SET_SHADOW 0x0008u
97#define ADC24_CTRL_SET_WEAK 0x0004u
98#define ADC24_CTRL_SET_RANGE_5V 0x0000u
99#define ADC24_CTRL_SET_RANGE_2_5V 0x0002u
100#define ADC24_CTRL_SET_CODING_2C 0x0000u
101#define ADC24_CTRL_SET_CODING_BIN 0x0001u
102
107#define ADC24_SEQ_SHADOW_AN_INPUT 0
108#define ADC24_SEQ_SHADOW_PROGRAMMING 1
109#define ADC24_SEQ_SHADOW_ALTERED 2
110#define ADC24_SEQ_SHADOW_ADDR_CONJ 3
111
116#define ADC24_CH_SEL_IN_0 0
117#define ADC24_CH_SEL_IN_1 1
118#define ADC24_CH_SEL_IN_2 2
119#define ADC24_CH_SEL_IN_3 3
120#define ADC24_CH_SEL_IN_4 4
121#define ADC24_CH_SEL_IN_5 5
122#define ADC24_CH_SEL_IN_6 6
123#define ADC24_CH_SEL_IN_7 7
124#define ADC24_CH_SEL_IN_8 8
125#define ADC24_CH_SEL_IN_9 9
126#define ADC24_CH_SEL_IN_10 10
127#define ADC24_CH_SEL_IN_11 11
128#define ADC24_CH_SEL_IN_12 12
129#define ADC24_CH_SEL_IN_13 13
130#define ADC24_CH_SEL_IN_14 14
131#define ADC24_CH_SEL_IN_15 15
132
137#define ADC24_PM_STANDBY 0
138#define ADC24_PM_AUTO_SHDN 1
139#define ADC24_PM_FULL_SHDN 2
140#define ADC24_PM_NORMAL 3
141
146#define ADC24_WEAK_DOUT_THREE_STATE 0
147#define ADC24_WEAK_DOUT_WEAKLY_DRIVEN 1
148
153#define ADC24_RANGE_VREF_5V 0
154#define ADC24_RANGE_VREF_2V5 1
155
160#define ADC24_CODING_2C 0
161#define ADC24_CODING_BIN 1
162
167#define ADC24_ADC_RESOLUTION 0x0FFF
168#define ADC24_VREF_2V5 2.5f
169#define ADC24_VREF_5V 5.0f
170
179#define ADC24_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
180#define ADC24_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
181
182 // adc24_set
183
198#define ADC24_MAP_MIKROBUS( cfg, mikrobus ) \
199 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
200 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
201 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
202 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
203
204 // adc24_map
205 // adc24
206
211typedef struct
212{
213 // Modules
214 spi_master_t spi;
216 pin_name_t chip_select;
218} adc24_t;
219
224typedef struct
225{
226 // Communication gpio pins
227 pin_name_t miso;
228 pin_name_t mosi;
229 pin_name_t sck;
230 pin_name_t cs;
232 // static variable
233 uint32_t spi_speed;
234 spi_master_mode_t spi_mode;
235 spi_master_chip_select_polarity_t cs_polarity;
238
243typedef struct
244{
245 uint8_t ch_sel;
246 uint8_t pm;
247 uint8_t seq_shadow;
248 uint8_t weak;
249 uint8_t range;
250 uint8_t coding;
253
258typedef enum
259{
261 ADC24_ERROR = -1
262
264
281
295err_t adc24_init ( adc24_t *ctx, adc24_cfg_t *cfg );
296
308err_t adc24_generic_write ( adc24_t *ctx, uint16_t control );
309
321err_t adc24_generic_read ( adc24_t *ctx, uint16_t *data_out );
322
337err_t adc24_get_adc_data ( adc24_t *ctx, adc24_ctrl_t ctrl, uint8_t *in_pos, uint16_t *adc_data );
338
354err_t adc24_get_voltage ( adc24_t *ctx, adc24_ctrl_t ctrl, uint8_t *in_pos, float *voltage );
355
356#ifdef __cplusplus
357}
358#endif
359#endif // ADC24_H
360
361 // adc24
362
363// ------------------------------------------------------------------------ END
adc24_return_value_t
ADC 24 Click return value data.
Definition adc24.h:259
@ ADC24_OK
Definition adc24.h:260
@ ADC24_ERROR
Definition adc24.h:261
err_t adc24_get_adc_data(adc24_t *ctx, adc24_ctrl_t ctrl, uint8_t *in_pos, uint16_t *adc_data)
ADC 24 get ADC data function.
err_t adc24_init(adc24_t *ctx, adc24_cfg_t *cfg)
ADC 24 initialization function.
void adc24_cfg_setup(adc24_cfg_t *cfg)
ADC 24 configuration object setup function.
err_t adc24_generic_read(adc24_t *ctx, uint16_t *data_out)
ADC 24 data reading function.
err_t adc24_get_voltage(adc24_t *ctx, adc24_ctrl_t ctrl, uint8_t *in_pos, float *voltage)
ADC 24 get voltage level function.
err_t adc24_generic_write(adc24_t *ctx, uint16_t control)
ADC 24 data writing function.
This file contains SPI specific macros, functions, etc.
ADC 24 Click configuration object.
Definition adc24.h:225
spi_master_chip_select_polarity_t cs_polarity
Definition adc24.h:235
pin_name_t sck
Definition adc24.h:229
spi_master_mode_t spi_mode
Definition adc24.h:234
pin_name_t mosi
Definition adc24.h:228
uint32_t spi_speed
Definition adc24.h:233
pin_name_t miso
Definition adc24.h:227
pin_name_t cs
Definition adc24.h:230
ADC 24 Click control object.
Definition adc24.h:244
uint8_t seq_shadow
Definition adc24.h:247
uint8_t pm
Definition adc24.h:246
uint8_t ch_sel
Definition adc24.h:245
uint8_t coding
Definition adc24.h:250
uint8_t weak
Definition adc24.h:248
uint8_t range
Definition adc24.h:249
ADC 24 Click context object.
Definition adc24.h:212
spi_master_t spi
Definition adc24.h:214
pin_name_t chip_select
Definition adc24.h:216