adc14 2.1.0.0
adc14.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 ADC14_H
29#define ADC14_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 ADC14_MEASURE_NUM 100
75#define ADC14_RESOLUTION_12BIT 0x0FFFu
76#define ADC14_RES_DIVIDER 4096.0f
77#define ADC14_CONVERT_V_T_MV 1000.0f
78
83#define ADC14_INT_VREF_2_048V 2.048f
84
89#define ADC14_EXT_VREF_0V 0.0f
90#define ADC14_EXT_VREF_3_3V 3.3f
91
92
97#define ADC14_MEASURE_NUM 100
98
107#define ADC14_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
108#define ADC14_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
109
110 // adc14_set
111
126#define ADC14_MAP_MIKROBUS( cfg, mikrobus ) \
127 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
128 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
129 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
130 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
131 cfg.shd = MIKROBUS( mikrobus, MIKROBUS_PWM )
132
133 // adc14_map
134 // adc14
135
140typedef struct
141{
142 // Output pins
143 digital_out_t shd;
145 // Modules
146 spi_master_t spi;
148 pin_name_t chip_select;
150 float vref;
152} adc14_t;
153
158typedef struct
159{
160 // Communication gpio pins
161 pin_name_t miso;
162 pin_name_t mosi;
163 pin_name_t sck;
164 pin_name_t cs;
166 // Additional gpio pins
167 pin_name_t shd;
169 // static variable
170 uint32_t spi_speed;
171 spi_master_mode_t spi_mode;
172 spi_master_chip_select_polarity_t cs_polarity;
174 float vref;
177
182typedef enum
183{
185 ADC14_ERROR = -1
186
188
205
219err_t adc14_init ( adc14_t *ctx, adc14_cfg_t *cfg );
220
232
246
260err_t adc14_read_conversion_data ( adc14_t *ctx, uint16_t *adc_data );
261
276err_t adc14_get_voltage ( adc14_t *ctx, float *voltage );
277
292err_t adc14_set_vref ( adc14_t *ctx, float vref );
293
294#ifdef __cplusplus
295}
296#endif
297#endif // ADC14_H
298
299 // adc14
300
301// ------------------------------------------------------------------------ END
adc14_return_value_t
ADC 14 Click return value data.
Definition adc14.h:183
@ ADC14_ERROR
Definition adc14.h:185
@ ADC14_OK
Definition adc14.h:184
err_t adc14_read_conversion_data(adc14_t *ctx, uint16_t *adc_data)
ADC 14 read conversion data function.
err_t adc14_get_voltage(adc14_t *ctx, float *voltage)
ADC 14 get voltage function.
err_t adc14_init(adc14_t *ctx, adc14_cfg_t *cfg)
ADC 14 initialization function.
void adc14_cfg_setup(adc14_cfg_t *cfg)
ADC 14 configuration object setup function.
err_t adc14_set_vref(adc14_t *ctx, float vref)
ADC 14 set voltage reference function.
void adc14_device_shutdown(adc14_t *ctx)
ADC 14 device shutdown function.
void adc14_device_power_up(adc14_t *ctx)
ADC 14 device shutdown function.
This file contains SPI specific macros, functions, etc.
ADC 14 Click configuration object.
Definition adc14.h:159
float vref
Definition adc14.h:174
spi_master_chip_select_polarity_t cs_polarity
Definition adc14.h:172
pin_name_t sck
Definition adc14.h:163
spi_master_mode_t spi_mode
Definition adc14.h:171
pin_name_t mosi
Definition adc14.h:162
uint32_t spi_speed
Definition adc14.h:170
pin_name_t shd
Definition adc14.h:167
pin_name_t miso
Definition adc14.h:161
pin_name_t cs
Definition adc14.h:164
ADC 14 Click context object.
Definition adc14.h:141
spi_master_t spi
Definition adc14.h:146
float vref
Definition adc14.h:150
pin_name_t chip_select
Definition adc14.h:148
digital_out_t shd
Definition adc14.h:143