adc15 2.0.0.0
adc15.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 ADC15_H
29#define ADC15_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 ADC15_CMD_NULL 0x0000
75#define ADC15_CMD_RESET 0x0011
76#define ADC15_CMD_STANDBY 0x0022
77#define ADC15_CMD_WAKEUP 0x0033
78#define ADC15_CMD_LOCK 0x0555
79#define ADC15_CMD_UNLOCK 0x0655
80#define ADC15_CMD_RREG 0xA000
81#define ADC15_CMD_WREG 0x6000
82
87#define ADC15_REG_ID 0x00
88#define ADC15_REG_STATUS 0x01
89#define ADC15_REG_MODE 0x02
90#define ADC15_REG_CLOCK 0x03
91#define ADC15_REG_GAIN 0x04
92#define ADC15_REG_CFG 0x06
93#define ADC15_REG_THRSHLD_MSB 0x07
94#define ADC15_REG_THRSHLD_LSB 0x08
95#define ADC15_REG_CH0_CFG 0x09
96#define ADC15_REG_CH0_OCAL_MSB 0x0A
97#define ADC15_REG_CH0_OCAL_LSB 0x0B
98#define ADC15_REG_CH0_GCAL_MSB 0x0C
99#define ADC15_REG_CH0_GCAL_LSB 0x0D
100#define ADC15_REG_CH1_CFG 0x0E
101#define ADC15_REG_CH1_OCAL_MSB 0x0F
102#define ADC15_REG_CH1_OCAL_LSB 0x10
103#define ADC15_REG_CH1_GCAL_MSB 0x11
104#define ADC15_REG_CH1_GCAL_LSB 0x12
105#define ADC15_REG_REGMAP_CRC 0x3E
106
107 // adc15_reg
108
124#define ADC15_FREQ_MODE_HIGH_RESOLUTION 8192000
125#define ADC15_FREQ_MODE_LOW_POWER 4096000
126#define ADC15_FREQ_MODE_VERY_LOW_POWER 2048000
127
132#define ADC15_LDC_CFG_POWER_ON 2
133#define ADC15_LDC_CFG_POWER_DOWN 3
134
143#define ADC15_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
144#define ADC15_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
145
146 // adc15_set
147
162#define ADC15_MAP_MIKROBUS( cfg, mikrobus ) \
163 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
164 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
165 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
166 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
167 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
168 cfg.cs2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
169 cfg.drdy = MIKROBUS( mikrobus, MIKROBUS_INT )
170
171 // adc15_map
172 // adc15
173
178typedef struct
179{
180 // Output pins
181 digital_out_t rst;
182 digital_out_t cs2;
184 // Input pins
185 digital_in_t drdy;
187 // Modules
188 spi_master_t spi;
190 pin_name_t chip_select;
192 uint8_t gain1;
193 uint8_t gain2;
194 uint8_t word_len;
195 uint32_t resolution;
197} adc15_t;
198
203typedef struct
204{
205 // Communication gpio pins
206 pin_name_t miso;
207 pin_name_t mosi;
208 pin_name_t sck;
209 pin_name_t cs;
211 // Additional gpio pins
212 pin_name_t rst;
213 pin_name_t cs2;
214 pin_name_t drdy;
216 // static variable
217 uint32_t spi_speed;
218 spi_master_mode_t spi_mode;
219 spi_master_chip_select_polarity_t cs_polarity;
222
227typedef enum
228{
230 ADC15_ERROR = -1
231
233
238typedef enum
239{
242
244
261
273
290
304err_t adc15_init ( adc15_t *ctx, adc15_cfg_t *cfg );
305
320
333err_t adc15_adc_write ( adc15_t *ctx, uint8_t *data_in, uint8_t len );
334
347err_t adc15_reg_write ( adc15_t *ctx, uint8_t reg, uint16_t data_in );
348
362err_t adc15_multiple_reg_write ( adc15_t *ctx, uint8_t reg, uint16_t *data_in, uint8_t data_size );
363
376err_t adc15_adc_read ( adc15_t *ctx, uint8_t *data_out, uint8_t len );
377
390err_t adc15_reg_read ( adc15_t *ctx, uint8_t reg, uint16_t *data_out );
391
405err_t adc15_multiple_reg_read ( adc15_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t data_size );
406
420err_t adc15_adc_transfer ( adc15_t *ctx, uint8_t *data_in, uint8_t *data_out, uint8_t len );
421
435err_t adc15_ltc_write ( adc15_t *ctx, uint8_t oct, uint16_t dac, uint8_t cfg );
436
448err_t adc15_set_frequency ( adc15_t *ctx, uint32_t frequency );
449
463err_t adc15_read_adc_value ( adc15_t *ctx, uint16_t *status, int32_t *ch1_out, int32_t *ch2_out );
464
479err_t adc15_read_voltage ( adc15_t *ctx, uint16_t *status, float *ch1_out, float *ch2_out );
480
489uint8_t adc15_data_ready ( adc15_t *ctx );
490
505
517err_t adc15_set_word_len ( adc15_t *ctx, adc15_word_t word_len );
518
519#ifdef __cplusplus
520}
521#endif
522#endif // ADC15_H
523
524 // adc15
525
526// ------------------------------------------------------------------------ END
adc15_gain_t
ADC 15 Click ADC gain configuration.
Definition adc15.h:250
@ ADC15_GAIN4
Definition adc15.h:253
@ ADC15_GAIN128
Definition adc15.h:258
@ ADC15_GAIN8
Definition adc15.h:254
@ ADC15_GAIN16
Definition adc15.h:255
@ ADC15_GAIN32
Definition adc15.h:256
@ ADC15_GAIN2
Definition adc15.h:252
@ ADC15_GAIN1
Definition adc15.h:251
@ ADC15_GAIN64
Definition adc15.h:257
adc15_channel_t
ADC 15 Click channel selection.
Definition adc15.h:239
@ ADC15_CHANNEL1
Definition adc15.h:240
@ ADC15_CHANNEL2
Definition adc15.h:241
adc15_word_t
ADC 15 Click communication word data length.
Definition adc15.h:267
@ ADC15_32bit
Definition adc15.h:270
@ ADC15_16bit
Definition adc15.h:268
@ ADC15_24bit
Definition adc15.h:269
adc15_return_value_t
ADC 15 Click return value data.
Definition adc15.h:228
@ ADC15_OK
Definition adc15.h:229
@ ADC15_ERROR
Definition adc15.h:230
void adc15_cfg_setup(adc15_cfg_t *cfg)
ADC 15 configuration object setup function.
err_t adc15_set_frequency(adc15_t *ctx, uint32_t frequency)
Set sampling frequency.
err_t adc15_set_word_len(adc15_t *ctx, adc15_word_t word_len)
Set word len.
err_t adc15_read_voltage(adc15_t *ctx, uint16_t *status, float *ch1_out, float *ch2_out)
Get voltage value.
err_t adc15_reg_write(adc15_t *ctx, uint8_t reg, uint16_t data_in)
Register writing function.
err_t adc15_reg_read(adc15_t *ctx, uint8_t reg, uint16_t *data_out)
Register reading function.
err_t adc15_adc_transfer(adc15_t *ctx, uint8_t *data_in, uint8_t *data_out, uint8_t len)
Data transfer function.
err_t adc15_multiple_reg_read(adc15_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t data_size)
Multiple registern reading function.
err_t adc15_multiple_reg_write(adc15_t *ctx, uint8_t reg, uint16_t *data_in, uint8_t data_size)
Multiple register writing function.
err_t adc15_adc_write(adc15_t *ctx, uint8_t *data_in, uint8_t len)
Data writing function.
err_t adc15_adc_read(adc15_t *ctx, uint8_t *data_out, uint8_t len)
Data reading function.
err_t adc15_init(adc15_t *ctx, adc15_cfg_t *cfg)
ADC 15 initialization function.
err_t adc15_set_gain(adc15_t *ctx, adc15_channel_t channel, adc15_gain_t gain)
Set gain for channel.
uint8_t adc15_data_ready(adc15_t *ctx)
Get data ready state.
err_t adc15_ltc_write(adc15_t *ctx, uint8_t oct, uint16_t dac, uint8_t cfg)
LTC writing function.
err_t adc15_read_adc_value(adc15_t *ctx, uint16_t *status, int32_t *ch1_out, int32_t *ch2_out)
Get raw adc value.
err_t adc15_default_cfg(adc15_t *ctx)
ADC 15 default configuration function.
This file contains SPI specific macros, functions, etc.
ADC 15 Click configuration object.
Definition adc15.h:204
pin_name_t drdy
Definition adc15.h:214
pin_name_t cs2
Definition adc15.h:213
spi_master_chip_select_polarity_t cs_polarity
Definition adc15.h:219
pin_name_t sck
Definition adc15.h:208
spi_master_mode_t spi_mode
Definition adc15.h:218
pin_name_t mosi
Definition adc15.h:207
uint32_t spi_speed
Definition adc15.h:217
pin_name_t miso
Definition adc15.h:206
pin_name_t rst
Definition adc15.h:212
pin_name_t cs
Definition adc15.h:209
ADC 15 Click context object.
Definition adc15.h:179
uint8_t gain2
Definition adc15.h:193
uint8_t gain1
Definition adc15.h:192
spi_master_t spi
Definition adc15.h:188
digital_in_t drdy
Definition adc15.h:185
uint8_t word_len
Definition adc15.h:194
digital_out_t rst
Definition adc15.h:181
digital_out_t cs2
Definition adc15.h:182
pin_name_t chip_select
Definition adc15.h:190
uint32_t resolution
Definition adc15.h:195