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 
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_i2c_master.h"
48 
69 #define HALLCURRENT7_RESOLUTION 4096
70 #define HALLCURRENT7_12_BIT_DATA 0x0FFF
71 #define HALLCURRENT7_ADC_NUM_OF_MEASURE 100.0
72 #define HALLCURRENT7_VREF_5000_mV 5000.0
73 
74 #define HALLCURRENT7_ACS770LCB_050B_SENS 0.04
75 
76 #define HALLCURRENT7_ERR_COR_FACTOR 1.05
77 
83 #define HALLCURRENT7_SET_DEV_ADDR 0x4D
84  // hallcurrent7_set
86 
101 #define HALLCURRENT7_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
103  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
104  // hallcurrent7_map // hallcurrent7
107 
112 typedef struct
113 {
114  // Modules
115  i2c_master_t i2c;
117  // I2C slave address
118  uint8_t slave_address;
121 
126 typedef struct
127 {
128  pin_name_t scl;
129  pin_name_t sda;
131  uint32_t i2c_speed;
132  uint8_t i2c_address;
135 
140 typedef enum
141 {
143  HALLCURRENT7_ERROR = -1
144 
146 
163 
178 
193 err_t hallcurrent7_generic_write ( hallcurrent7_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
194 
209 err_t hallcurrent7_generic_read ( hallcurrent7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
210 
219 
228 uint16_t hallcurrent7_read_voltage ( hallcurrent7_t *ctx, uint16_t v_ref );
229 
238 int16_t hallcurrent7_calc_current ( hallcurrent7_t *ctx, uint16_t v_ref );
239 
248 int16_t hallcurrent7_avg_current ( hallcurrent7_t *ctx, uint16_t v_ref );
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // HALLCURRENT7_H
254  // hallcurrent7
256 
257 // ------------------------------------------------------------------------ END
hallcurrent7_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent7.h:132
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:113
HALLCURRENT7_ERROR
@ HALLCURRENT7_ERROR
Definition: hallcurrent7.h:143
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:118
HALLCURRENT7_OK
@ HALLCURRENT7_OK
Definition: hallcurrent7.h:142
hallcurrent7_return_value_t
hallcurrent7_return_value_t
Hall Current 7 Click return value data.
Definition: hallcurrent7.h:141
hallcurrent7_cfg_t::sda
pin_name_t sda
Definition: hallcurrent7.h:129
hallcurrent7_cfg_t::scl
pin_name_t scl
Definition: hallcurrent7.h:128
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:115
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:127
hallcurrent7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent7.h:131
hallcurrent7_cfg_setup
void hallcurrent7_cfg_setup(hallcurrent7_cfg_t *cfg)
Hall Current 7 configuration object setup function.