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
32extern "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
89 // 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
109 // hallcurrent7_map
110 // hallcurrent7
111
116typedef struct
117{
118 // Modules
119 i2c_master_t i2c;
121 // I2C slave address
125
130typedef struct
131{
132 pin_name_t scl;
133 pin_name_t sda;
135 uint32_t i2c_speed;
136 uint8_t i2c_address;
139
150
167
182
197err_t hallcurrent7_generic_write ( hallcurrent7_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
198
213err_t hallcurrent7_generic_read ( hallcurrent7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
214
223
232uint16_t hallcurrent7_read_voltage ( hallcurrent7_t *ctx, uint16_t v_ref );
233
242int16_t hallcurrent7_calc_current ( hallcurrent7_t *ctx, uint16_t v_ref );
243
252int16_t hallcurrent7_avg_current ( hallcurrent7_t *ctx, uint16_t v_ref );
253
254#ifdef __cplusplus
255}
256#endif
257#endif // HALLCURRENT7_H
258
259 // hallcurrent7
260
261// ------------------------------------------------------------------------ END
uint16_t hallcurrent7_read_voltage(hallcurrent7_t *ctx, uint16_t v_ref)
Read voltage function.
uint16_t hallcurrent7_read_data(hallcurrent7_t *ctx)
Read data function.
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.
void hallcurrent7_cfg_setup(hallcurrent7_cfg_t *cfg)
Hall Current 7 configuration object setup function.
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.
int16_t hallcurrent7_avg_current(hallcurrent7_t *ctx, uint16_t v_ref)
Calculate Average current function.
int16_t hallcurrent7_calc_current(hallcurrent7_t *ctx, uint16_t v_ref)
Calculate current function.
err_t hallcurrent7_init(hallcurrent7_t *ctx, hallcurrent7_cfg_t *cfg)
Hall Current 7 initialization function.
hallcurrent7_return_value_t
Hall Current 7 Click return value data.
Definition hallcurrent7.h:145
@ HALLCURRENT7_OK
Definition hallcurrent7.h:146
@ HALLCURRENT7_ERROR
Definition hallcurrent7.h:147
Hall Current 7 Click configuration object.
Definition hallcurrent7.h:131
uint32_t i2c_speed
Definition hallcurrent7.h:135
pin_name_t scl
Definition hallcurrent7.h:132
pin_name_t sda
Definition hallcurrent7.h:133
uint8_t i2c_address
Definition hallcurrent7.h:136
Hall Current 7 Click context object.
Definition hallcurrent7.h:117
i2c_master_t i2c
Definition hallcurrent7.h:119
uint8_t slave_address
Definition hallcurrent7.h:122