adc12 2.0.0.0
adc12.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 ADC12_H
29#define ADC12_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_i2c_master.h"
52
73#define ADC12_CMD_SD_MASK 0x80
74#define ADC12_CMD_SD_DIFF 0x00
75#define ADC12_CMD_SD_SINGLE_END 0x80
76
77#define ADC12_CMD_PD_MASK 0x0C
78#define ADC12_CMD_PD_PDADCONV 0x00
79#define ADC12_CMD_PD_IROFF_ADON 0x04
80#define ADC12_CMD_PD_IRON_ADOFF 0x08
81#define ADC12_CMD_PD_IRON_ADON 0x0C
82
83 // adc12_cmd
84
99#define ADC12_SINGLE_END_CH0 0
100#define ADC12_SINGLE_END_CH1 1
101#define ADC12_SINGLE_END_CH2 2
102#define ADC12_SINGLE_END_CH3 3
103#define ADC12_SINGLE_END_CH4 4
104#define ADC12_SINGLE_END_CH5 5
105#define ADC12_SINGLE_END_CH6 6
106#define ADC12_SINGLE_END_CH7 7
107
112#define ADC12_DIFF_CH0_P_CH1_N 0
113#define ADC12_DIFF_CH1_P_CH0_N 1
114#define ADC12_DIFF_CH2_P_CH3_N 2
115#define ADC12_DIFF_CH3_P_CH2_N 3
116#define ADC12_DIFF_CH4_P_CH5_N 4
117#define ADC12_DIFF_CH5_P_CH4_N 5
118#define ADC12_DIFF_CH6_P_CH7_N 6
119#define ADC12_DIFF_CH7_P_CH6_N 7
120
125#define ADC12_INTERNAL_VREF 2500
126
131#define ADC12_RES 4096.0
132
138#define ADC12_DEV_ADDR_DEFAULT 0x48
139#define ADC12_DEV_ADDR_01 0x49
140#define ADC12_DEV_ADDR_10 0x4A
141#define ADC12_DEV_ADDR_11 0x4B
142
143 // adc12_set
144
159#define ADC12_MAP_MIKROBUS( cfg, mikrobus ) \
160 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
161 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
162
163 // adc12_map
164 // adc12
165
170typedef struct
171{
172 // Modules
173
174 i2c_master_t i2c;
176 // I2C slave address
177
183} adc12_t;
184
189typedef struct
190{
191 pin_name_t scl;
192 pin_name_t sda;
194 uint32_t i2c_speed;
195 uint8_t i2c_address;
198
203typedef enum
204{
206 ADC12_ERROR = -1
207
209
228
245err_t adc12_init ( adc12_t *ctx, adc12_cfg_t *cfg );
246
261err_t adc12_send_cmd ( adc12_t *ctx, uint8_t cmd_byte );
262
277err_t adc12_read_data ( adc12_t *ctx, uint16_t *data_out );
278
290void adc12_set_sd_mode ( adc12_t *ctx, uint8_t sd_mode );
291
302uint8_t adc12_get_sd_mode ( adc12_t *ctx );
303
315void adc12_set_pd_mode ( adc12_t *ctx, uint8_t pd_mode );
316
327uint8_t adc12_get_pd_mode ( adc12_t *ctx );
328
344err_t adc12_read_raw_data ( adc12_t *ctx, uint8_t ch, uint16_t *data_out );
345
362err_t adc12_read_voltage ( adc12_t *ctx, uint8_t ch, uint16_t vref, float *data_out );
363
364#ifdef __cplusplus
365}
366#endif
367#endif // ADC12_H
368
369 // adc12
370
371// ------------------------------------------------------------------------ END
adc12_return_value_t
ADC 12 Click return value data.
Definition adc12.h:204
@ ADC12_ERROR
Definition adc12.h:206
@ ADC12_OK
Definition adc12.h:205
err_t adc12_send_cmd(adc12_t *ctx, uint8_t cmd_byte)
ADC 12 send command function.
err_t adc12_read_data(adc12_t *ctx, uint16_t *data_out)
ADC 12 read data function.
uint8_t adc12_get_sd_mode(adc12_t *ctx)
ADC 12 get the Single-Ended/Differential Inputs function.
err_t adc12_read_raw_data(adc12_t *ctx, uint8_t ch, uint16_t *data_out)
ADC 12 read raw ADC data function.
err_t adc12_init(adc12_t *ctx, adc12_cfg_t *cfg)
ADC 12 initialization function.
void adc12_set_pd_mode(adc12_t *ctx, uint8_t pd_mode)
ADC 12 set the Power-Down mode function.
err_t adc12_read_voltage(adc12_t *ctx, uint8_t ch, uint16_t vref, float *data_out)
ADC 12 read voltage function.
void adc12_set_sd_mode(adc12_t *ctx, uint8_t sd_mode)
ADC 12 set the Single-Ended/Differential Inputs function.
void adc12_cfg_setup(adc12_cfg_t *cfg)
ADC 12 configuration object setup function.
uint8_t adc12_get_pd_mode(adc12_t *ctx)
ADC 12 get the Power-Down mode function.
ADC 12 Click configuration object.
Definition adc12.h:190
uint32_t i2c_speed
Definition adc12.h:194
pin_name_t scl
Definition adc12.h:191
pin_name_t sda
Definition adc12.h:192
uint8_t i2c_address
Definition adc12.h:195
ADC 12 Click context object.
Definition adc12.h:171
uint8_t adc12_pd_mode
Definition adc12.h:181
uint8_t adc12_sd_mode
Definition adc12.h:180
i2c_master_t i2c
Definition adc12.h:174
uint8_t slave_address
Definition adc12.h:178