hallcurrent22 2.2.0
Loading...
Searching...
No Matches
hallcurrent22.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
27
28#ifndef HALLCURRENT22_H
29#define HALLCURRENT22_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_analog_in.h"
52#include "drv_i2c_master.h"
53
59
64
69
74#define HALLCURRENT22_NUM_CONVERSIONS 200
75
80#define HALLCURRENT22_ADC_RESOLUTION 0x0FFF
81#define HALLCURRENT22_VREF_3V3 3.35
82
87#define HALLCURRENT22_TIMEOUT_MS 2000
88
94#define HALLCURRENT22_SET_DEV_ADDR 0x4D
95 // hallcurrent22_set
97
102
107
112#define HALLCURRENT22_MAP_MIKROBUS( cfg, mikrobus ) \
113 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
114 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
115 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
116 // hallcurrent22_map // hallcurrent22
119
130
135typedef struct
136{
137 analog_in_t adc;
138 i2c_master_t i2c;
139
141 float vref;
145
147
152typedef struct
153{
154 pin_name_t an;
155 pin_name_t scl;
156 pin_name_t sda;
157
158 analog_in_resolution_t resolution;
159 float vref;
160
161 uint32_t i2c_speed;
162 uint8_t i2c_address;
163
165
167
178
184
195
211
226
238err_t hallcurrent22_read_raw_adc ( hallcurrent22_t *ctx, uint16_t *raw_adc );
239
251err_t hallcurrent22_read_voltage ( hallcurrent22_t *ctx, float *voltage );
252
265err_t hallcurrent22_read_voltage_avg ( hallcurrent22_t *ctx, uint16_t num_conv, float *voltage_avg );
266
278err_t hallcurrent22_set_vref ( hallcurrent22_t *ctx, float vref );
279
291
304err_t hallcurrent22_calib_resolution ( hallcurrent22_t *ctx, float calib_current );
305
318err_t hallcurrent22_read_current ( hallcurrent22_t *ctx, float *current );
319
320#ifdef __cplusplus
321}
322#endif
323#endif // HALLCURRENT22_H
324 // hallcurrent22
326
327// ------------------------------------------------------------------------ END
err_t hallcurrent22_read_voltage(hallcurrent22_t *ctx, float *voltage)
Hall Current 22 read voltage level function.
err_t hallcurrent22_read_raw_adc(hallcurrent22_t *ctx, uint16_t *raw_adc)
Hall Current 22 read raw ADC value function.
err_t hallcurrent22_init(hallcurrent22_t *ctx, hallcurrent22_cfg_t *cfg)
Hall Current 22 initialization function.
err_t hallcurrent22_calib_offset(hallcurrent22_t *ctx)
Hall Current 22 calib offset function.
err_t hallcurrent22_set_vref(hallcurrent22_t *ctx, float vref)
Hall Current 22 set vref function.
void hallcurrent22_drv_interface_sel(hallcurrent22_cfg_t *cfg, hallcurrent22_drv_t drv_sel)
Hall Current 22 driver interface setup function.
err_t hallcurrent22_read_current(hallcurrent22_t *ctx, float *current)
Hall Current 22 read current function.
void hallcurrent22_cfg_setup(hallcurrent22_cfg_t *cfg)
Hall Current 22 configuration object setup function.
err_t hallcurrent22_read_voltage_avg(hallcurrent22_t *ctx, uint16_t num_conv, float *voltage_avg)
Hall Current 22 read average voltage level function.
err_t hallcurrent22_calib_resolution(hallcurrent22_t *ctx, float calib_current)
Hall Current 22 calib resolution function.
hallcurrent22_return_value_t
Hall Current 22 Click return value data.
Definition hallcurrent22.h:173
@ HALLCURRENT22_OK
Definition hallcurrent22.h:174
@ HALLCURRENT22_ERROR
Definition hallcurrent22.h:175
hallcurrent22_drv_t
Hall Current 22 Click driver selector.
Definition hallcurrent22.h:125
@ HALLCURRENT22_DRV_SEL_ADC
Definition hallcurrent22.h:126
@ HALLCURRENT22_DRV_SEL_I2C
Definition hallcurrent22.h:127
Hall Current 22 Click configuration object.
Definition hallcurrent22.h:153
analog_in_resolution_t resolution
Definition hallcurrent22.h:158
float vref
Definition hallcurrent22.h:159
uint32_t i2c_speed
Definition hallcurrent22.h:161
hallcurrent22_drv_t drv_sel
Definition hallcurrent22.h:164
pin_name_t scl
Definition hallcurrent22.h:155
pin_name_t sda
Definition hallcurrent22.h:156
pin_name_t an
Definition hallcurrent22.h:154
uint8_t i2c_address
Definition hallcurrent22.h:162
Hall Current 22 Click context object.
Definition hallcurrent22.h:136
float data_resolution
Definition hallcurrent22.h:143
float vref
Definition hallcurrent22.h:141
hallcurrent22_drv_t drv_sel
Definition hallcurrent22.h:144
i2c_master_t i2c
Definition hallcurrent22.h:138
uint8_t slave_address
Definition hallcurrent22.h:140
float zero_curr_offset
Definition hallcurrent22.h:142
analog_in_t adc
Definition hallcurrent22.h:137