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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define ISOADC3_RESOLUTION 4096
60 #define ISOADC3_OFFSET 1287
61 #define ISOADC3_ADC_NUM_OF_MEASURE 100.0
62 #define ISOADC3_12_BIT_DATA 0x0FFF
63 #define ISOADC3_GAIN 4
64 
70 #define ISOADC3_VREF_3V3 3336
71 #define ISOADC3_VREF_5V 5070
72 
78 #define ISOADC3_SET_DEV_ADDR 0x4D
79  // isoadc3_set
81 
96 #define ISOADC3_MAP_MIKROBUS( cfg, mikrobus ) \
97  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
98  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
99  // isoadc3_map // isoadc3
102 
107 typedef struct
108 {
109  // Modules
110  i2c_master_t i2c;
112  // I2C slave address
113  uint8_t slave_address;
115 } isoadc3_t;
116 
121 typedef struct
122 {
123  pin_name_t scl;
124  pin_name_t sda;
126  uint32_t i2c_speed;
127  uint8_t i2c_address;
129 } isoadc3_cfg_t;
130 
135 typedef enum
136 {
138  ISOADC3_ERROR = -1
139 
141 
158 
173 err_t isoadc3_init ( isoadc3_t *ctx, isoadc3_cfg_t *cfg );
174 
190 err_t isoadc3_generic_write ( isoadc3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
191 
206 err_t isoadc3_generic_read ( isoadc3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
207 
215 uint16_t isoadc3_read_adc ( isoadc3_t *ctx );
216 
225 uint16_t isoadc3_get_adc_voltage ( isoadc3_t *ctx, uint16_t v_ref );
226 
235 uint16_t isoadc3_read_voltage ( isoadc3_t *ctx, uint16_t v_ref );
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 #endif // ISOADC3_H
241  // isoadc3
243 
244 // ------------------------------------------------------------------------ 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:124
isoadc3_t
ISO ADC 3 Click context object.
Definition: isoadc3.h:108
isoadc3_t::i2c
i2c_master_t i2c
Definition: isoadc3.h:110
isoadc3_cfg_t::i2c_address
uint8_t i2c_address
Definition: isoadc3.h:127
isoadc3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: isoadc3.h:126
ISOADC3_OK
@ ISOADC3_OK
Definition: isoadc3.h:137
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:123
isoadc3_cfg_t
ISO ADC 3 Click configuration object.
Definition: isoadc3.h:122
isoadc3_return_value_t
isoadc3_return_value_t
ISO ADC 3 Click return value data.
Definition: isoadc3.h:136
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:113
ISOADC3_ERROR
@ ISOADC3_ERROR
Definition: isoadc3.h:138