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 
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 ISOADC3_RESOLUTION 4096
70 #define ISOADC3_OFFSET 1287
71 #define ISOADC3_ADC_NUM_OF_MEASURE 100.0
72 #define ISOADC3_12_BIT_DATA 0x0FFF
73 #define ISOADC3_GAIN 4
74 
80 #define ISOADC3_VREF_3V3 3336
81 #define ISOADC3_VREF_5V 5070
82 
88 #define ISOADC3_SET_DEV_ADDR 0x4D
89  // isoadc3_set
91 
106 #define ISOADC3_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
108  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
109  // isoadc3_map // isoadc3
112 
117 typedef struct
118 {
119  // Modules
120  i2c_master_t i2c;
122  // I2C slave address
123  uint8_t slave_address;
125 } isoadc3_t;
126 
131 typedef struct
132 {
133  pin_name_t scl;
134  pin_name_t sda;
136  uint32_t i2c_speed;
137  uint8_t i2c_address;
139 } isoadc3_cfg_t;
140 
145 typedef enum
146 {
148  ISOADC3_ERROR = -1
149 
151 
168 
183 err_t isoadc3_init ( isoadc3_t *ctx, isoadc3_cfg_t *cfg );
184 
200 err_t isoadc3_generic_write ( isoadc3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
201 
216 err_t isoadc3_generic_read ( isoadc3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
217 
225 uint16_t isoadc3_read_adc ( isoadc3_t *ctx );
226 
235 uint16_t isoadc3_get_adc_voltage ( isoadc3_t *ctx, uint16_t v_ref );
236 
245 uint16_t isoadc3_read_voltage ( isoadc3_t *ctx, uint16_t v_ref );
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 #endif // ISOADC3_H
251  // isoadc3
253 
254 // ------------------------------------------------------------------------ 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:134
isoadc3_t
ISO ADC 3 Click context object.
Definition: isoadc3.h:118
isoadc3_t::i2c
i2c_master_t i2c
Definition: isoadc3.h:120
isoadc3_cfg_t::i2c_address
uint8_t i2c_address
Definition: isoadc3.h:137
isoadc3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: isoadc3.h:136
ISOADC3_OK
@ ISOADC3_OK
Definition: isoadc3.h:147
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:133
isoadc3_cfg_t
ISO ADC 3 Click configuration object.
Definition: isoadc3.h:132
isoadc3_return_value_t
isoadc3_return_value_t
ISO ADC 3 Click return value data.
Definition: isoadc3.h:146
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:123
ISOADC3_ERROR
@ ISOADC3_ERROR
Definition: isoadc3.h:148