isoadc3  2.0.0.0
isoadc3.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 ISOADC3_H
29 #define ISOADC3_H
30 
31 #ifdef __cplusplus
32 extern "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 ISOADC3_RESOLUTION 4096
74 #define ISOADC3_OFFSET 1287
75 #define ISOADC3_ADC_NUM_OF_MEASURE 100.0
76 #define ISOADC3_12_BIT_DATA 0x0FFF
77 #define ISOADC3_GAIN 4
78 
84 #define ISOADC3_VREF_3V3 3336
85 #define ISOADC3_VREF_5V 5070
86 
92 #define ISOADC3_SET_DEV_ADDR 0x4D
93  // isoadc3_set
95 
110 #define ISOADC3_MAP_MIKROBUS( cfg, mikrobus ) \
111  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
112  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
113  // isoadc3_map // isoadc3
116 
121 typedef struct
122 {
123  // Modules
124  i2c_master_t i2c;
126  // I2C slave address
127  uint8_t slave_address;
129 } isoadc3_t;
130 
135 typedef struct
136 {
137  pin_name_t scl;
138  pin_name_t sda;
140  uint32_t i2c_speed;
141  uint8_t i2c_address;
143 } isoadc3_cfg_t;
144 
149 typedef enum
150 {
152  ISOADC3_ERROR = -1
153 
155 
172 
187 err_t isoadc3_init ( isoadc3_t *ctx, isoadc3_cfg_t *cfg );
188 
204 err_t isoadc3_generic_write ( isoadc3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
205 
220 err_t isoadc3_generic_read ( isoadc3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
221 
229 uint16_t isoadc3_read_adc ( isoadc3_t *ctx );
230 
239 uint16_t isoadc3_get_adc_voltage ( isoadc3_t *ctx, uint16_t v_ref );
240 
249 uint16_t isoadc3_read_voltage ( isoadc3_t *ctx, uint16_t v_ref );
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 #endif // ISOADC3_H
255  // isoadc3
257 
258 // ------------------------------------------------------------------------ END
isoadc3_generic_write
err_t isoadc3_generic_write(isoadc3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
ISO ADC 3 I2C writing function.
isoadc3_get_adc_voltage
uint16_t isoadc3_get_adc_voltage(isoadc3_t *ctx, uint16_t v_ref)
Read ADC voltage function.
isoadc3_cfg_setup
void isoadc3_cfg_setup(isoadc3_cfg_t *cfg)
ISO ADC 3 configuration object setup function.
isoadc3_cfg_t::sda
pin_name_t sda
Definition: isoadc3.h:138
isoadc3_t
ISO ADC 3 Click context object.
Definition: isoadc3.h:122
isoadc3_t::i2c
i2c_master_t i2c
Definition: isoadc3.h:124
isoadc3_cfg_t::i2c_address
uint8_t i2c_address
Definition: isoadc3.h:141
isoadc3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: isoadc3.h:140
ISOADC3_OK
@ ISOADC3_OK
Definition: isoadc3.h:151
isoadc3_generic_read
err_t isoadc3_generic_read(isoadc3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
ISO ADC 3 I2C reading function.
isoadc3_read_voltage
uint16_t isoadc3_read_voltage(isoadc3_t *ctx, uint16_t v_ref)
Read voltage function.
isoadc3_cfg_t::scl
pin_name_t scl
Definition: isoadc3.h:137
isoadc3_cfg_t
ISO ADC 3 Click configuration object.
Definition: isoadc3.h:136
isoadc3_return_value_t
isoadc3_return_value_t
ISO ADC 3 Click return value data.
Definition: isoadc3.h:150
isoadc3_init
err_t isoadc3_init(isoadc3_t *ctx, isoadc3_cfg_t *cfg)
ISO ADC 3 initialization function.
isoadc3_read_adc
uint16_t isoadc3_read_adc(isoadc3_t *ctx)
Read ADC function.
isoadc3_t::slave_address
uint8_t slave_address
Definition: isoadc3.h:127
ISOADC3_ERROR
@ ISOADC3_ERROR
Definition: isoadc3.h:152