hallcurrent7  2.0.0.0
hallcurrent7.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2021 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 HALLCURRENT7_H
29 #define HALLCURRENT7_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_i2c_master.h"
52 
73 #define HALLCURRENT7_RESOLUTION 4096
74 #define HALLCURRENT7_12_BIT_DATA 0x0FFF
75 #define HALLCURRENT7_ADC_NUM_OF_MEASURE 100.0
76 #define HALLCURRENT7_VREF_5000_mV 5000.0
77 
78 #define HALLCURRENT7_ACS770LCB_050B_SENS 0.04
79 
80 #define HALLCURRENT7_ERR_COR_FACTOR 1.05
81 
87 #define HALLCURRENT7_SET_DEV_ADDR 0x4D
88  // hallcurrent7_set
90 
105 #define HALLCURRENT7_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
107  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
108  // hallcurrent7_map // hallcurrent7
111 
116 typedef struct
117 {
118  // Modules
119  i2c_master_t i2c;
121  // I2C slave address
122  uint8_t slave_address;
125 
130 typedef struct
131 {
132  pin_name_t scl;
133  pin_name_t sda;
135  uint32_t i2c_speed;
136  uint8_t i2c_address;
139 
144 typedef enum
145 {
147  HALLCURRENT7_ERROR = -1
148 
150 
167 
182 
197 err_t hallcurrent7_generic_write ( hallcurrent7_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
198 
213 err_t hallcurrent7_generic_read ( hallcurrent7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
214 
223 
232 uint16_t hallcurrent7_read_voltage ( hallcurrent7_t *ctx, uint16_t v_ref );
233 
242 int16_t hallcurrent7_calc_current ( hallcurrent7_t *ctx, uint16_t v_ref );
243 
252 int16_t hallcurrent7_avg_current ( hallcurrent7_t *ctx, uint16_t v_ref );
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #endif // HALLCURRENT7_H
258  // hallcurrent7
260 
261 // ------------------------------------------------------------------------ END
hallcurrent7_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent7.h:136
hallcurrent7_read_voltage
uint16_t hallcurrent7_read_voltage(hallcurrent7_t *ctx, uint16_t v_ref)
Read voltage function.
hallcurrent7_t
Hall Current 7 Click context object.
Definition: hallcurrent7.h:117
HALLCURRENT7_ERROR
@ HALLCURRENT7_ERROR
Definition: hallcurrent7.h:147
hallcurrent7_generic_write
err_t hallcurrent7_generic_write(hallcurrent7_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Hall Current 7 I2C writing function.
hallcurrent7_t::slave_address
uint8_t slave_address
Definition: hallcurrent7.h:122
HALLCURRENT7_OK
@ HALLCURRENT7_OK
Definition: hallcurrent7.h:146
hallcurrent7_return_value_t
hallcurrent7_return_value_t
Hall Current 7 Click return value data.
Definition: hallcurrent7.h:145
hallcurrent7_cfg_t::sda
pin_name_t sda
Definition: hallcurrent7.h:133
hallcurrent7_cfg_t::scl
pin_name_t scl
Definition: hallcurrent7.h:132
hallcurrent7_avg_current
int16_t hallcurrent7_avg_current(hallcurrent7_t *ctx, uint16_t v_ref)
Calculate Average current function.
hallcurrent7_t::i2c
i2c_master_t i2c
Definition: hallcurrent7.h:119
hallcurrent7_read_data
uint16_t hallcurrent7_read_data(hallcurrent7_t *ctx)
Read data function.
hallcurrent7_calc_current
int16_t hallcurrent7_calc_current(hallcurrent7_t *ctx, uint16_t v_ref)
Calculate current function.
hallcurrent7_generic_read
err_t hallcurrent7_generic_read(hallcurrent7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Hall Current 7 I2C reading function.
hallcurrent7_init
err_t hallcurrent7_init(hallcurrent7_t *ctx, hallcurrent7_cfg_t *cfg)
Hall Current 7 initialization function.
hallcurrent7_cfg_t
Hall Current 7 Click configuration object.
Definition: hallcurrent7.h:131
hallcurrent7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent7.h:135
hallcurrent7_cfg_setup
void hallcurrent7_cfg_setup(hallcurrent7_cfg_t *cfg)
Hall Current 7 configuration object setup function.