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 "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_analog_in.h"
48 #include "drv_i2c_master.h"
49 
70 #define CURRENT9_SENSITIVITY_V_TO_A 0.1333
71 #define CURRENT9_ZERO_CURRENT_OFFSET 0.500
72 #define CURRENT9_NUM_CONVERSIONS 200
73 #define CURRENT9_SENSOR_OUT_DIVIDER_2 2.0
74 #define CURRENT9_90PCT_VCC 4.5
75 
80 #define CURRENT9_ADC_RESOLUTION 0x0FFF
81 #define CURRENT9_VREF_3V3 3.3
82 #define CURRENT9_VREF_5V 5.0
83 
89 #define CURRENT9_SET_DEV_ADDR 0x4D
90  // current9_set
92 
107 #define CURRENT9_MAP_MIKROBUS( cfg, mikrobus ) \
108  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
109  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
110  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
111  // current9_map // current9
114 
119 typedef enum
120 {
125 
130 typedef struct
131 {
132  analog_in_t adc;
133  i2c_master_t i2c;
135  uint8_t slave_address;
136  pin_name_t chip_select;
137  float vref;
140 } current9_t;
141 
146 typedef struct
147 {
148  pin_name_t an;
149  pin_name_t scl;
150  pin_name_t sda;
152  analog_in_resolution_t resolution;
153  float vref;
155  uint32_t i2c_speed;
156  uint8_t i2c_address;
161 
166 typedef enum
167 {
169  CURRENT9_ERROR = -1
170 
172 
189 
205 
220 
232 err_t current9_read_raw_adc ( current9_t *ctx, uint16_t *raw_adc );
233 
245 err_t current9_read_voltage ( current9_t *ctx, float *voltage );
246 
258 err_t current9_set_vref ( current9_t *ctx, float vref );
259 
274 err_t current9_read_current ( current9_t *ctx, float *current );
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // CURRENT9_H
280  // current9
282 
283 // ------------------------------------------------------------------------ END
current9_cfg_t::i2c_address
uint8_t i2c_address
Definition: current9.h:156
CURRENT9_DRV_SEL_I2C
@ CURRENT9_DRV_SEL_I2C
Definition: current9.h:122
current9_cfg_t::sda
pin_name_t sda
Definition: current9.h:150
current9_return_value_t
current9_return_value_t
Current 9 Click return value data.
Definition: current9.h:167
current9_t::drv_sel
current9_drv_t drv_sel
Definition: current9.h:138
current9_t::chip_select
pin_name_t chip_select
Definition: current9.h:136
current9_cfg_t
Current 9 Click configuration object.
Definition: current9.h:147
CURRENT9_DRV_SEL_ADC
@ CURRENT9_DRV_SEL_ADC
Definition: current9.h:121
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:149
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:152
current9_cfg_t::an
pin_name_t an
Definition: current9.h:148
current9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: current9.h:155
current9_cfg_t::drv_sel
current9_drv_t drv_sel
Definition: current9.h:158
current9_t::i2c
i2c_master_t i2c
Definition: current9.h:133
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:169
current9_t::adc
analog_in_t adc
Definition: current9.h:132
current9_t
Current 9 Click context object.
Definition: current9.h:131
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:153
current9_drv_t
current9_drv_t
Current 9 Click driver selector.
Definition: current9.h:120
CURRENT9_OK
@ CURRENT9_OK
Definition: current9.h:168
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:137
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:135