hallcurrent15 2.0.0.0
hallcurrent15.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 HALLCURRENT15_H
29#define HALLCURRENT15_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
74#define HALLCURRENT15_REG_CONVERSION_RESULT 0x00
75#define HALLCURRENT15_REG_ALERT_STATUS 0x01
76#define HALLCURRENT15_REG_CONFIGURATION 0x02
77#define HALLCURRENT15_REG_LOW_LIMIT 0x03
78#define HALLCURRENT15_REG_HIGH_LIMIT 0x04
79#define HALLCURRENT15_REG_HYSTERESIS 0x05
80#define HALLCURRENT15_REG_LOWEST_CONVERSION 0x06
81#define HALLCURRENT15_REG_HIGHEST_CONVERSION 0x07
82
83 // hallcurrent15_reg
84
99#define HALLCURRENT15_SENSITIVITY_V_TO_A 0.05
100#define HALLCURRENT15_ZERO_CURRENT_OFFSET 0.1
101#define HALLCURRENT15_NUM_CONVERSIONS 1000
102
107#define HALLCURRENT15_ADC_RESOLUTION 0x03FF
108#define HALLCURRENT15_VREF_3V3 3.3
109#define HALLCURRENT15_VREF_5V 5.0
110
116#define HALLCURRENT15_SET_DEV_ADDR 0x54
117
118 // hallcurrent15_set
119
134#define HALLCURRENT15_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
136 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
137 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
138 cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
139
140 // hallcurrent15_map
141 // hallcurrent15
142
153
158typedef struct
159{
160 digital_in_t alr;
162 analog_in_t adc;
163 i2c_master_t i2c;
166 pin_name_t chip_select;
167 float vref;
171
176typedef struct
177{
178 pin_name_t an;
179 pin_name_t scl;
180 pin_name_t sda;
181 pin_name_t alr;
183 analog_in_resolution_t resolution;
184 float vref;
186 uint32_t i2c_speed;
187 uint8_t i2c_address;
192
203
220
236
251
264err_t hallcurrent15_write_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t data_in );
265
278err_t hallcurrent15_read_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t *data_out );
279
289
301err_t hallcurrent15_read_raw_adc ( hallcurrent15_t *ctx, uint16_t *raw_adc );
302
314err_t hallcurrent15_read_voltage ( hallcurrent15_t *ctx, float *voltage );
315
327err_t hallcurrent15_set_vref ( hallcurrent15_t *ctx, float vref );
328
342err_t hallcurrent15_read_current ( hallcurrent15_t *ctx, float *current );
343
344#ifdef __cplusplus
345}
346#endif
347#endif // HALLCURRENT15_H
348
349 // hallcurrent15
350
351// ------------------------------------------------------------------------ END
err_t hallcurrent15_read_current(hallcurrent15_t *ctx, float *current)
Hall Current 15 read current function.
void hallcurrent15_drv_interface_selection(hallcurrent15_cfg_t *cfg, hallcurrent15_drv_t drv_sel)
Hall Current 15 driver interface setup function.
err_t hallcurrent15_write_register(hallcurrent15_t *ctx, uint8_t reg, uint16_t data_in)
Hall Current 15 write register function.
void hallcurrent15_cfg_setup(hallcurrent15_cfg_t *cfg)
Hall Current 15 configuration object setup function.
uint8_t hallcurrent15_get_alert_pin(hallcurrent15_t *ctx)
Hall Current 15 get alert pin function.
err_t hallcurrent15_read_register(hallcurrent15_t *ctx, uint8_t reg, uint16_t *data_out)
Hall Current 15 read register function.
err_t hallcurrent15_set_vref(hallcurrent15_t *ctx, float vref)
Hall Current 15 set vref function.
err_t hallcurrent15_read_voltage(hallcurrent15_t *ctx, float *voltage)
Hall Current 15 read voltage level function.
err_t hallcurrent15_read_raw_adc(hallcurrent15_t *ctx, uint16_t *raw_adc)
Hall Current 15 read raw ADC value function.
err_t hallcurrent15_init(hallcurrent15_t *ctx, hallcurrent15_cfg_t *cfg)
Hall Current 15 initialization function.
hallcurrent15_drv_t
Hall Current 15 Click driver selector.
Definition hallcurrent15.h:148
@ HALLCURRENT15_DRV_SEL_I2C
Definition hallcurrent15.h:150
@ HALLCURRENT15_DRV_SEL_ADC
Definition hallcurrent15.h:149
hallcurrent15_return_value_t
Hall Current 15 Click return value data.
Definition hallcurrent15.h:198
@ HALLCURRENT15_OK
Definition hallcurrent15.h:199
@ HALLCURRENT15_ERROR
Definition hallcurrent15.h:200
Hall Current 15 Click configuration object.
Definition hallcurrent15.h:177
analog_in_resolution_t resolution
Definition hallcurrent15.h:183
float vref
Definition hallcurrent15.h:184
pin_name_t alr
Definition hallcurrent15.h:181
uint32_t i2c_speed
Definition hallcurrent15.h:186
hallcurrent15_drv_t drv_sel
Definition hallcurrent15.h:189
pin_name_t scl
Definition hallcurrent15.h:179
pin_name_t sda
Definition hallcurrent15.h:180
pin_name_t an
Definition hallcurrent15.h:178
uint8_t i2c_address
Definition hallcurrent15.h:187
Hall Current 15 Click context object.
Definition hallcurrent15.h:159
digital_in_t alr
Definition hallcurrent15.h:160
float vref
Definition hallcurrent15.h:167
hallcurrent15_drv_t drv_sel
Definition hallcurrent15.h:168
i2c_master_t i2c
Definition hallcurrent15.h:163
uint8_t slave_address
Definition hallcurrent15.h:165
pin_name_t chip_select
Definition hallcurrent15.h:166
analog_in_t adc
Definition hallcurrent15.h:162