hallcurrent14  2.0.0.0
hallcurrent14.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 HALLCURRENT14_H
29 #define HALLCURRENT14_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_analog_in.h"
52 #include "drv_i2c_master.h"
53 
74 #define HALLCURRENT14_SENSITIVITY_V_TO_A 0.08
75 #define HALLCURRENT14_ZERO_CURRENT_OFFSET 0.5
76 #define HALLCURRENT14_NUM_CONVERSIONS 1000
77 
82 #define HALLCURRENT14_ADC_RESOLUTION 0x0FFF
83 #define HALLCURRENT14_VREF_5V 5.0
84 
90 #define HALLCURRENT14_SET_DEV_ADDR 0x4D
91  // hallcurrent14_set
93 
108 #define HALLCURRENT14_MAP_MIKROBUS( cfg, mikrobus ) \
109  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
111  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
112  // hallcurrent14_map // hallcurrent14
115 
120 typedef enum
121 {
126 
131 typedef struct
132 {
133  analog_in_t adc;
134  i2c_master_t i2c;
136  uint8_t slave_address;
137  pin_name_t chip_select;
138  float vref;
142 
147 typedef struct
148 {
149  pin_name_t an;
150  pin_name_t scl;
151  pin_name_t sda;
153  analog_in_resolution_t resolution;
154  float vref;
156  uint32_t i2c_speed;
157  uint8_t i2c_address;
162 
167 typedef enum
168 {
171 
173 
190 
206 
221 
233 err_t hallcurrent14_read_raw_adc ( hallcurrent14_t *ctx, uint16_t *raw_adc );
234 
246 err_t hallcurrent14_read_voltage ( hallcurrent14_t *ctx, float *voltage );
247 
259 err_t hallcurrent14_set_vref ( hallcurrent14_t *ctx, float vref );
260 
274 err_t hallcurrent14_read_current ( hallcurrent14_t *ctx, float *current );
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // HALLCURRENT14_H
280  // hallcurrent14
282 
283 // ------------------------------------------------------------------------ END
hallcurrent14_t
Hall Current 14 Click context object.
Definition: hallcurrent14.h:132
hallcurrent14_t::chip_select
pin_name_t chip_select
Definition: hallcurrent14.h:137
hallcurrent14_return_value_t
hallcurrent14_return_value_t
Hall Current 14 Click return value data.
Definition: hallcurrent14.h:168
hallcurrent14_t::vref
float vref
Definition: hallcurrent14.h:138
hallcurrent14_init
err_t hallcurrent14_init(hallcurrent14_t *ctx, hallcurrent14_cfg_t *cfg)
Hall Current 14 initialization function.
hallcurrent14_read_raw_adc
err_t hallcurrent14_read_raw_adc(hallcurrent14_t *ctx, uint16_t *raw_adc)
Hall Current 14 read raw ADC value function.
hallcurrent14_cfg_t
Hall Current 14 Click configuration object.
Definition: hallcurrent14.h:148
hallcurrent14_t::drv_sel
hallcurrent14_drv_t drv_sel
Definition: hallcurrent14.h:139
HALLCURRENT14_DRV_SEL_ADC
@ HALLCURRENT14_DRV_SEL_ADC
Definition: hallcurrent14.h:122
hallcurrent14_t::i2c
i2c_master_t i2c
Definition: hallcurrent14.h:134
HALLCURRENT14_DRV_SEL_I2C
@ HALLCURRENT14_DRV_SEL_I2C
Definition: hallcurrent14.h:123
hallcurrent14_cfg_setup
void hallcurrent14_cfg_setup(hallcurrent14_cfg_t *cfg)
Hall Current 14 configuration object setup function.
hallcurrent14_cfg_t::sda
pin_name_t sda
Definition: hallcurrent14.h:151
hallcurrent14_cfg_t::vref
float vref
Definition: hallcurrent14.h:154
HALLCURRENT14_ERROR
@ HALLCURRENT14_ERROR
Definition: hallcurrent14.h:170
hallcurrent14_cfg_t::an
pin_name_t an
Definition: hallcurrent14.h:149
hallcurrent14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent14.h:156
hallcurrent14_t::adc
analog_in_t adc
Definition: hallcurrent14.h:133
hallcurrent14_drv_t
hallcurrent14_drv_t
Hall Current 14 Click driver selector.
Definition: hallcurrent14.h:121
hallcurrent14_cfg_t::scl
pin_name_t scl
Definition: hallcurrent14.h:150
hallcurrent14_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent14.h:157
HALLCURRENT14_OK
@ HALLCURRENT14_OK
Definition: hallcurrent14.h:169
hallcurrent14_read_voltage
err_t hallcurrent14_read_voltage(hallcurrent14_t *ctx, float *voltage)
Hall Current 14 read voltage level function.
hallcurrent14_cfg_t::resolution
analog_in_resolution_t resolution
Definition: hallcurrent14.h:153
hallcurrent14_read_current
err_t hallcurrent14_read_current(hallcurrent14_t *ctx, float *current)
Hall Current 14 read current function.
hallcurrent14_set_vref
err_t hallcurrent14_set_vref(hallcurrent14_t *ctx, float vref)
Hall Current 14 set vref function.
hallcurrent14_t::slave_address
uint8_t slave_address
Definition: hallcurrent14.h:136
hallcurrent14_drv_interface_selection
void hallcurrent14_drv_interface_selection(hallcurrent14_cfg_t *cfg, hallcurrent14_drv_t drv_sel)
Hall Current 14 driver interface setup function.
hallcurrent14_cfg_t::drv_sel
hallcurrent14_drv_t drv_sel
Definition: hallcurrent14.h:159