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
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_i2c_master.h"
38
59#define ADC12_CMD_SD_MASK 0x80
60#define ADC12_CMD_SD_DIFF 0x00
61#define ADC12_CMD_SD_SINGLE_END 0x80
62
63#define ADC12_CMD_PD_MASK 0x0C
64#define ADC12_CMD_PD_PDADCONV 0x00
65#define ADC12_CMD_PD_IROFF_ADON 0x04
66#define ADC12_CMD_PD_IRON_ADOFF 0x08
67#define ADC12_CMD_PD_IRON_ADON 0x0C
68 // adc12_cmd
70
85#define ADC12_SINGLE_END_CH0 0
86#define ADC12_SINGLE_END_CH1 1
87#define ADC12_SINGLE_END_CH2 2
88#define ADC12_SINGLE_END_CH3 3
89#define ADC12_SINGLE_END_CH4 4
90#define ADC12_SINGLE_END_CH5 5
91#define ADC12_SINGLE_END_CH6 6
92#define ADC12_SINGLE_END_CH7 7
93
98#define ADC12_DIFF_CH0_P_CH1_N 0
99#define ADC12_DIFF_CH1_P_CH0_N 1
100#define ADC12_DIFF_CH2_P_CH3_N 2
101#define ADC12_DIFF_CH3_P_CH2_N 3
102#define ADC12_DIFF_CH4_P_CH5_N 4
103#define ADC12_DIFF_CH5_P_CH4_N 5
104#define ADC12_DIFF_CH6_P_CH7_N 6
105#define ADC12_DIFF_CH7_P_CH6_N 7
106
111#define ADC12_INTERNAL_VREF 2500
112
117#define ADC12_RES 4096.0
118
124#define ADC12_DEV_ADDR_DEFAULT 0x48
125#define ADC12_DEV_ADDR_01 0x49
126#define ADC12_DEV_ADDR_10 0x4A
127#define ADC12_DEV_ADDR_11 0x4B
128 // adc12_set
130
145#define ADC12_MAP_MIKROBUS( cfg, mikrobus ) \
146 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
147 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
148 // adc12_map // adc12
151
156typedef struct
157{
158 // Modules
159
160 i2c_master_t i2c;
162 // I2C slave address
163
169} adc12_t;
170
175typedef struct
176{
177 pin_name_t scl;
178 pin_name_t sda;
180 uint32_t i2c_speed;
181 uint8_t i2c_address;
184
189typedef enum
190{
192 ADC12_ERROR = -1
193
195
214
231err_t adc12_init ( adc12_t *ctx, adc12_cfg_t *cfg );
232
247err_t adc12_send_cmd ( adc12_t *ctx, uint8_t cmd_byte );
248
263err_t adc12_read_data ( adc12_t *ctx, uint16_t *data_out );
264
276void adc12_set_sd_mode ( adc12_t *ctx, uint8_t sd_mode );
277
288uint8_t adc12_get_sd_mode ( adc12_t *ctx );
289
301void adc12_set_pd_mode ( adc12_t *ctx, uint8_t pd_mode );
302
313uint8_t adc12_get_pd_mode ( adc12_t *ctx );
314
330err_t adc12_read_raw_data ( adc12_t *ctx, uint8_t ch, uint16_t *data_out );
331
348err_t adc12_read_voltage ( adc12_t *ctx, uint8_t ch, uint16_t vref, float *data_out );
349
350#ifdef __cplusplus
351}
352#endif
353#endif // ADC12_H
354 // adc12
356
357// ------------------------------------------------------------------------ END
adc12_return_value_t
ADC 12 Click return value data.
Definition: adc12.h:190
@ ADC12_ERROR
Definition: adc12.h:192
@ ADC12_OK
Definition: adc12.h:191
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:176
uint32_t i2c_speed
Definition: adc12.h:180
pin_name_t scl
Definition: adc12.h:177
pin_name_t sda
Definition: adc12.h:178
uint8_t i2c_address
Definition: adc12.h:181
ADC 12 Click context object.
Definition: adc12.h:157
uint8_t adc12_pd_mode
Definition: adc12.h:167
uint8_t adc12_sd_mode
Definition: adc12.h:166
i2c_master_t i2c
Definition: adc12.h:160
uint8_t slave_address
Definition: adc12.h:164