hallcurrent18 2.1.0.0
hallcurrent18.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 HALLCURRENT18_H
29#define HALLCURRENT18_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
75#define HALLCURRENT18_ADC_RESOLUTION 0x0FFFu
76#define HALLCURRENT18_VREF_3V3 3.3f
77#define HALLCURRENT18_VREF_5V 5.0f
78#define HALLCURRENT18_HALF_SCALE_3V3 1.65f
79
84#define HALLCURRENT18_SENSITIVITY_MV_A 33.0f
85#define HALLCURRENT18_CONV_TO_MILI 1000.0f
86#define HALLCURRENT18_ADC_NUM_OF_MEASURE 500u
87
93#define HALLCURRENT18_SET_DEV_ADDR 0x4D
94
95 // hallcurrent18_set
96
111#define HALLCURRENT18_MAP_MIKROBUS( cfg, mikrobus ) \
112 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
113 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
114 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
115
116 // hallcurrent18_map
117 // hallcurrent18
118
129
134typedef struct
135{
136 analog_in_t adc;
137 i2c_master_t i2c;
140 float vref;
141 float zero_vref;
145
150typedef struct
151{
152 pin_name_t an;
153 pin_name_t scl;
154 pin_name_t sda;
156 analog_in_resolution_t resolution;
157 float vref;
158 float zero_vref;
160 uint32_t i2c_speed;
161 uint8_t i2c_address;
166
177
194
210
225
239
251err_t hallcurrent18_read_raw_adc ( hallcurrent18_t *ctx, uint16_t *raw_adc );
252
264err_t hallcurrent18_read_voltage ( hallcurrent18_t *ctx, float *voltage );
265
277err_t hallcurrent18_set_vref ( hallcurrent18_t *ctx, float vref );
278
292err_t hallcurrent18_read_current ( hallcurrent18_t *ctx, float *current );
293
307
308#ifdef __cplusplus
309}
310#endif
311#endif // HALLCURRENT18_H
312
313 // hallcurrent18
314
315// ------------------------------------------------------------------------ END
err_t hallcurrent18_read_voltage(hallcurrent18_t *ctx, float *voltage)
Hall Current 18 read voltage level function.
err_t hallcurrent18_read_raw_adc(hallcurrent18_t *ctx, uint16_t *raw_adc)
Hall Current 18 read raw ADC value function.
void hallcurrent18_drv_interface_selection(hallcurrent18_cfg_t *cfg, hallcurrent18_drv_t drv_sel)
Hall Current 18 driver interface setup function.
err_t hallcurrent18_init(hallcurrent18_t *ctx, hallcurrent18_cfg_t *cfg)
Hall Current 18 initialization function.
err_t hallcurrent18_default_cfg(hallcurrent18_t *ctx)
Hall Current 18 default configuration function.
err_t hallcurrent18_set_vref(hallcurrent18_t *ctx, float vref)
Hall Current 18 set vref function.
err_t hallcurrent18_set_zero_ref(hallcurrent18_t *ctx)
Hall Current 18 set zero reference function.
err_t hallcurrent18_read_current(hallcurrent18_t *ctx, float *current)
Hall Current 18 get current function.
void hallcurrent18_cfg_setup(hallcurrent18_cfg_t *cfg)
Hall Current 18 configuration object setup function.
hallcurrent18_drv_t
Hall Current 18 Click driver selector.
Definition hallcurrent18.h:124
@ HALLCURRENT18_DRV_SEL_I2C
Definition hallcurrent18.h:126
@ HALLCURRENT18_DRV_SEL_ADC
Definition hallcurrent18.h:125
hallcurrent18_return_value_t
Hall Current 18 Click return value data.
Definition hallcurrent18.h:172
@ HALLCURRENT18_OK
Definition hallcurrent18.h:173
@ HALLCURRENT18_ERROR
Definition hallcurrent18.h:174
Hall Current 18 Click configuration object.
Definition hallcurrent18.h:151
analog_in_resolution_t resolution
Definition hallcurrent18.h:156
float vref
Definition hallcurrent18.h:157
uint32_t i2c_speed
Definition hallcurrent18.h:160
float zero_vref
Definition hallcurrent18.h:158
hallcurrent18_drv_t drv_sel
Definition hallcurrent18.h:163
pin_name_t scl
Definition hallcurrent18.h:153
pin_name_t sda
Definition hallcurrent18.h:154
pin_name_t an
Definition hallcurrent18.h:152
uint8_t i2c_address
Definition hallcurrent18.h:161
Hall Current 18 Click context object.
Definition hallcurrent18.h:135
float vref
Definition hallcurrent18.h:140
float zero_vref
Definition hallcurrent18.h:141
i2c_master_t i2c
Definition hallcurrent18.h:137
hallcurrent18_drv_t drv_sel
Definition hallcurrent18.h:142
uint8_t slave_address
Definition hallcurrent18.h:139
analog_in_t adc
Definition hallcurrent18.h:136