current9  2.1.0.0
current9.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 CURRENT9_H
29 #define CURRENT9_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_analog_in.h"
38 #include "drv_i2c_master.h"
39 
60 #define CURRENT9_SENSITIVITY_V_TO_A 0.1333
61 #define CURRENT9_ZERO_CURRENT_OFFSET 0.500
62 #define CURRENT9_NUM_CONVERSIONS 200
63 #define CURRENT9_SENSOR_OUT_DIVIDER_2 2.0
64 #define CURRENT9_90PCT_VCC 4.5
65 
70 #define CURRENT9_ADC_RESOLUTION 0x0FFF
71 #define CURRENT9_VREF_3V3 3.3
72 #define CURRENT9_VREF_5V 5.0
73 
79 #define CURRENT9_SET_DEV_ADDR 0x4D
80  // current9_set
82 
97 #define CURRENT9_MAP_MIKROBUS( cfg, mikrobus ) \
98  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
99  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
100  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
101  // current9_map // current9
104 
109 typedef enum
110 {
115 
120 typedef struct
121 {
122  analog_in_t adc;
123  i2c_master_t i2c;
125  uint8_t slave_address;
126  pin_name_t chip_select;
127  float vref;
130 } current9_t;
131 
136 typedef struct
137 {
138  pin_name_t an;
139  pin_name_t scl;
140  pin_name_t sda;
142  analog_in_resolution_t resolution;
143  float vref;
145  uint32_t i2c_speed;
146  uint8_t i2c_address;
151 
156 typedef enum
157 {
159  CURRENT9_ERROR = -1
160 
162 
179 
195 
210 
222 err_t current9_read_raw_adc ( current9_t *ctx, uint16_t *raw_adc );
223 
235 err_t current9_read_voltage ( current9_t *ctx, float *voltage );
236 
248 err_t current9_set_vref ( current9_t *ctx, float vref );
249 
264 err_t current9_read_current ( current9_t *ctx, float *current );
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 #endif // CURRENT9_H
270  // current9
272 
273 // ------------------------------------------------------------------------ END
current9_cfg_t::i2c_address
uint8_t i2c_address
Definition: current9.h:146
CURRENT9_DRV_SEL_I2C
@ CURRENT9_DRV_SEL_I2C
Definition: current9.h:112
current9_cfg_t::sda
pin_name_t sda
Definition: current9.h:140
current9_return_value_t
current9_return_value_t
Current 9 Click return value data.
Definition: current9.h:157
current9_t::drv_sel
current9_drv_t drv_sel
Definition: current9.h:128
current9_t::chip_select
pin_name_t chip_select
Definition: current9.h:126
current9_cfg_t
Current 9 Click configuration object.
Definition: current9.h:137
CURRENT9_DRV_SEL_ADC
@ CURRENT9_DRV_SEL_ADC
Definition: current9.h:111
current9_init
err_t current9_init(current9_t *ctx, current9_cfg_t *cfg)
Current 9 initialization function.
current9_cfg_t::scl
pin_name_t scl
Definition: current9.h:139
current9_drv_interface_selection
void current9_drv_interface_selection(current9_cfg_t *cfg, current9_drv_t drv_sel)
Current 9 driver interface setup function.
current9_cfg_t::resolution
analog_in_resolution_t resolution
Definition: current9.h:142
current9_cfg_t::an
pin_name_t an
Definition: current9.h:138
current9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: current9.h:145
current9_cfg_t::drv_sel
current9_drv_t drv_sel
Definition: current9.h:148
current9_t::i2c
i2c_master_t i2c
Definition: current9.h:123
current9_read_current
err_t current9_read_current(current9_t *ctx, float *current)
Current 9 read current function.
CURRENT9_ERROR
@ CURRENT9_ERROR
Definition: current9.h:159
current9_t::adc
analog_in_t adc
Definition: current9.h:122
current9_t
Current 9 Click context object.
Definition: current9.h:121
current9_cfg_setup
void current9_cfg_setup(current9_cfg_t *cfg)
Current 9 configuration object setup function.
current9_cfg_t::vref
float vref
Definition: current9.h:143
current9_drv_t
current9_drv_t
Current 9 Click driver selector.
Definition: current9.h:110
CURRENT9_OK
@ CURRENT9_OK
Definition: current9.h:158
current9_set_vref
err_t current9_set_vref(current9_t *ctx, float vref)
Current 9 set vref function.
current9_t::vref
float vref
Definition: current9.h:127
current9_read_voltage
err_t current9_read_voltage(current9_t *ctx, float *voltage)
Current 9 read voltage level function.
current9_read_raw_adc
err_t current9_read_raw_adc(current9_t *ctx, uint16_t *raw_adc)
Current 9 read raw ADC value function.
current9_t::slave_address
uint8_t slave_address
Definition: current9.h:125