hallcurrent13  2.0.0.0
hallcurrent13.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 HALLCURRENT13_H
29 #define HALLCURRENT13_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 HALLCURRENT13_SENSITIVITY_V_TO_A 0.1
75 #define HALLCURRENT13_ZERO_CURRENT_OFFSET 0.1
76 #define HALLCURRENT13_NUM_CONVERSIONS 100
77 
82 #define HALLCURRENT13_ADC_RESOLUTION 0x0FFF
83 #define HALLCURRENT13_VREF_3V3 3.3
84 #define HALLCURRENT13_VREF_5V 5.0
85 
91 #define HALLCURRENT13_SET_DEV_ADDR 0x4D
92  // hallcurrent13_set
94 
109 #define HALLCURRENT13_MAP_MIKROBUS( cfg, mikrobus ) \
110  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
111  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
112  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
113  // hallcurrent13_map // hallcurrent13
116 
121 typedef enum
122 {
127 
132 typedef struct
133 {
134  analog_in_t adc;
135  i2c_master_t i2c;
137  uint8_t slave_address;
138  pin_name_t chip_select;
139  float vref;
143 
148 typedef struct
149 {
150  pin_name_t an;
151  pin_name_t scl;
152  pin_name_t sda;
154  analog_in_resolution_t resolution;
155  float vref;
157  uint32_t i2c_speed;
158  uint8_t i2c_address;
163 
168 typedef enum
169 {
172 
174 
191 
207 
223 
236 err_t hallcurrent13_read_raw_adc ( hallcurrent13_t *ctx, uint16_t *raw_adc );
237 
250 err_t hallcurrent13_read_voltage ( hallcurrent13_t *ctx, float *voltage );
251 
264 err_t hallcurrent13_set_vref ( hallcurrent13_t *ctx, float vref );
265 
279 err_t hallcurrent13_read_current ( hallcurrent13_t *ctx, float *current );
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif // HALLCURRENT13_H
285  // hallcurrent13
287 
288 // ------------------------------------------------------------------------ END
hallcurrent13_read_voltage
err_t hallcurrent13_read_voltage(hallcurrent13_t *ctx, float *voltage)
Hall Current 13 read voltage level function.
hallcurrent13_drv_interface_selection
void hallcurrent13_drv_interface_selection(hallcurrent13_cfg_t *cfg, hallcurrent13_drv_t drv_sel)
Hall Current 13 driver interface setup function.
hallcurrent13_t::chip_select
pin_name_t chip_select
Definition: hallcurrent13.h:138
hallcurrent13_set_vref
err_t hallcurrent13_set_vref(hallcurrent13_t *ctx, float vref)
Hall Current 13 set vref function.
HALLCURRENT13_ERROR
@ HALLCURRENT13_ERROR
Definition: hallcurrent13.h:171
hallcurrent13_return_value_t
hallcurrent13_return_value_t
Hall Current 13 Click return value data.
Definition: hallcurrent13.h:169
hallcurrent13_t::drv_sel
hallcurrent13_drv_t drv_sel
Definition: hallcurrent13.h:140
hallcurrent13_cfg_t
Hall Current 13 Click configuration object.
Definition: hallcurrent13.h:149
hallcurrent13_cfg_t::scl
pin_name_t scl
Definition: hallcurrent13.h:151
hallcurrent13_init
err_t hallcurrent13_init(hallcurrent13_t *ctx, hallcurrent13_cfg_t *cfg)
Hall Current 13 initialization function.
hallcurrent13_t::i2c
i2c_master_t i2c
Definition: hallcurrent13.h:135
hallcurrent13_cfg_t::drv_sel
hallcurrent13_drv_t drv_sel
Definition: hallcurrent13.h:160
HALLCURRENT13_DRV_SEL_ADC
@ HALLCURRENT13_DRV_SEL_ADC
Definition: hallcurrent13.h:123
hallcurrent13_read_current
err_t hallcurrent13_read_current(hallcurrent13_t *ctx, float *current)
Hall Current 13 read current function.
HALLCURRENT13_OK
@ HALLCURRENT13_OK
Definition: hallcurrent13.h:170
hallcurrent13_drv_t
hallcurrent13_drv_t
Hall Current 13 Click driver selector.
Definition: hallcurrent13.h:122
hallcurrent13_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent13.h:158
hallcurrent13_t::vref
float vref
Definition: hallcurrent13.h:139
HALLCURRENT13_DRV_SEL_I2C
@ HALLCURRENT13_DRV_SEL_I2C
Definition: hallcurrent13.h:124
hallcurrent13_cfg_t::resolution
analog_in_resolution_t resolution
Definition: hallcurrent13.h:154
hallcurrent13_t::adc
analog_in_t adc
Definition: hallcurrent13.h:134
hallcurrent13_read_raw_adc
err_t hallcurrent13_read_raw_adc(hallcurrent13_t *ctx, uint16_t *raw_adc)
Hall Current 13 read raw ADC value function.
hallcurrent13_cfg_t::sda
pin_name_t sda
Definition: hallcurrent13.h:152
hallcurrent13_cfg_t::vref
float vref
Definition: hallcurrent13.h:155
hallcurrent13_t::slave_address
uint8_t slave_address
Definition: hallcurrent13.h:137
hallcurrent13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent13.h:157
hallcurrent13_cfg_setup
void hallcurrent13_cfg_setup(hallcurrent13_cfg_t *cfg)
Hall Current 13 configuration object setup function.
hallcurrent13_t
Hall Current 13 Click context object.
Definition: hallcurrent13.h:133
hallcurrent13_cfg_t::an
pin_name_t an
Definition: hallcurrent13.h:150