adc17  2.0.0.0
adc17.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 ADC17_H
29 #define ADC17_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define ADC17_REG_SETUP 0x80
70 #define ADC17_SETUP_VREF_VDD_REF_NC_OFF 0x00
71 #define ADC17_SETUP_VREF_EXT_REF_IN_OFF 0x20
72 #define ADC17_SETUP_VREF_INT_REF_NC_OFF 0x40
73 #define ADC17_SETUP_VREF_INT_REF_NC_ON 0x50
74 #define ADC17_SETUP_VREF_INT_REF_OUT_OFF 0x60
75 #define ADC17_SETUP_VREF_INT_REF_OUT_ON 0x70
76 #define ADC17_SETUP_CLK_INT 0x00
77 #define ADC17_SETUP_CLK_EXT 0x08
78 #define ADC17_SETUP_UNIPOLAR 0x00
79 #define ADC17_SETUP_BIPOLAR 0x04
80 #define ADC17_SETUP_RST_RESET 0x00
81 #define ADC17_SETUP_RST_NO_ACTION 0x02
82 
87 #define ADC17_REG_CONFIG 0x00
88 #define ADC17_CONFIG_SCAN_AIN0_TO_CS0 0x00
89 #define ADC17_CONFIG_SCAN_CS0_8_TIMES 0x20
90 #define ADC17_CONFIG_SCAN_CS0 0x60
91 #define ADC17_CONFIG_CS0_AIN0 0x00
92 #define ADC17_CONFIG_CS0_AIN1 0x02
93 #define ADC17_CONFIG_DIFFERENTIAL 0x00
94 #define ADC17_CONFIG_SINGLE_ENDED 0x01
95 
100 #define ADC17_REG_BIT_MASK 0x80
101 #define ADC17_SETUP_VREF_BIT_MASK 0x70
102 #define ADC17_SETUP_CLK_BIT_MASK 0x08
103 #define ADC17_SETUP_UNI_BIP_BIT_MASK 0x04
104 #define ADC17_SETUP_RST_BIT_MASK 0x02
105 #define ADC17_CONFIG_SCAN_BIT_MASK 0x60
106 #define ADC17_CONFIG_CS0_BIT_MASK 0x02
107 #define ADC17_CONFIG_SGL_DIF_BIT_MASK 0x01
108 
113 #define ADC17_CHANNEL_0 0
114 #define ADC17_CHANNEL_1 1
115 
120 #define ADC17_RESOLUTION 0x0FFF
121 #define ADC17_VREF 2.048
122 
128 #define ADC17_SET_DEV_ADDR 0x36
129  // adc17_set
131 
146 #define ADC17_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
148  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
149  // adc17_map // adc17
152 
157 typedef struct
158 {
159  // Modules
160  i2c_master_t i2c;
162  // I2C slave address
163  uint8_t slave_address;
165  uint8_t setup_byte;
166  uint8_t config_byte;
168 } adc17_t;
169 
174 typedef struct
175 {
176  pin_name_t scl;
177  pin_name_t sda;
179  uint32_t i2c_speed;
180  uint8_t i2c_address;
182 } adc17_cfg_t;
183 
188 typedef enum
189 {
190  ADC17_OK = 0,
191  ADC17_ERROR = -1
192 
194 
211 
226 err_t adc17_init ( adc17_t *ctx, adc17_cfg_t *cfg );
227 
241 err_t adc17_default_cfg ( adc17_t *ctx );
242 
255 err_t adc17_write_setup_byte ( adc17_t *ctx, uint8_t setup_byte );
256 
269 err_t adc17_write_config_byte ( adc17_t *ctx, uint8_t config_byte );
270 
283 err_t adc17_set_channel ( adc17_t *ctx, uint8_t channel );
284 
298 err_t adc17_get_voltage ( adc17_t *ctx, float *voltage );
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 #endif // ADC17_H
304  // adc17
306 
307 // ------------------------------------------------------------------------ END
adc17_set_channel
err_t adc17_set_channel(adc17_t *ctx, uint8_t channel)
ADC 17 set channel function.
adc17_default_cfg
err_t adc17_default_cfg(adc17_t *ctx)
ADC 17 default configuration function.
ADC17_ERROR
@ ADC17_ERROR
Definition: adc17.h:191
adc17_get_voltage
err_t adc17_get_voltage(adc17_t *ctx, float *voltage)
ADC 17 get voltage function.
adc17_return_value_t
adc17_return_value_t
ADC 17 Click return value data.
Definition: adc17.h:189
adc17_cfg_t::i2c_address
uint8_t i2c_address
Definition: adc17.h:180
adc17_cfg_setup
void adc17_cfg_setup(adc17_cfg_t *cfg)
ADC 17 configuration object setup function.
adc17_t::setup_byte
uint8_t setup_byte
Definition: adc17.h:165
adc17_cfg_t::sda
pin_name_t sda
Definition: adc17.h:177
adc17_init
err_t adc17_init(adc17_t *ctx, adc17_cfg_t *cfg)
ADC 17 initialization function.
adc17_t::config_byte
uint8_t config_byte
Definition: adc17.h:166
ADC17_OK
@ ADC17_OK
Definition: adc17.h:190
adc17_cfg_t
ADC 17 Click configuration object.
Definition: adc17.h:175
adc17_t::slave_address
uint8_t slave_address
Definition: adc17.h:163
adc17_write_config_byte
err_t adc17_write_config_byte(adc17_t *ctx, uint8_t config_byte)
ADC 17 write config byte function.
adc17_t::i2c
i2c_master_t i2c
Definition: adc17.h:160
adc17_cfg_t::scl
pin_name_t scl
Definition: adc17.h:176
adc17_t
ADC 17 Click context object.
Definition: adc17.h:158
adc17_write_setup_byte
err_t adc17_write_setup_byte(adc17_t *ctx, uint8_t setup_byte)
ADC 17 write setup byte function.
adc17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: adc17.h:179