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
32 extern "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  // 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  // 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  // hallcurrent15_map // hallcurrent15
142 
147 typedef enum
148 {
153 
158 typedef struct
159 {
160  digital_in_t alr;
162  analog_in_t adc;
163  i2c_master_t i2c;
165  uint8_t slave_address;
166  pin_name_t chip_select;
167  float vref;
171 
176 typedef 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 
197 typedef enum
198 {
201 
203 
220 
236 
251 
264 err_t hallcurrent15_write_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t data_in );
265 
278 err_t hallcurrent15_read_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t *data_out );
279 
289 
301 err_t hallcurrent15_read_raw_adc ( hallcurrent15_t *ctx, uint16_t *raw_adc );
302 
314 err_t hallcurrent15_read_voltage ( hallcurrent15_t *ctx, float *voltage );
315 
327 err_t hallcurrent15_set_vref ( hallcurrent15_t *ctx, float vref );
328 
342 err_t hallcurrent15_read_current ( hallcurrent15_t *ctx, float *current );
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif // HALLCURRENT15_H
348  // hallcurrent15
350 
351 // ------------------------------------------------------------------------ END
hallcurrent15_get_alert_pin
uint8_t hallcurrent15_get_alert_pin(hallcurrent15_t *ctx)
Hall Current 15 get alert pin function.
hallcurrent15_read_register
err_t hallcurrent15_read_register(hallcurrent15_t *ctx, uint8_t reg, uint16_t *data_out)
Hall Current 15 read register function.
HALLCURRENT15_DRV_SEL_I2C
@ HALLCURRENT15_DRV_SEL_I2C
Definition: hallcurrent15.h:150
hallcurrent15_return_value_t
hallcurrent15_return_value_t
Hall Current 15 Click return value data.
Definition: hallcurrent15.h:198
hallcurrent15_cfg_t::sda
pin_name_t sda
Definition: hallcurrent15.h:180
hallcurrent15_t::alr
digital_in_t alr
Definition: hallcurrent15.h:160
hallcurrent15_read_raw_adc
err_t hallcurrent15_read_raw_adc(hallcurrent15_t *ctx, uint16_t *raw_adc)
Hall Current 15 read raw ADC value function.
HALLCURRENT15_DRV_SEL_ADC
@ HALLCURRENT15_DRV_SEL_ADC
Definition: hallcurrent15.h:149
hallcurrent15_set_vref
err_t hallcurrent15_set_vref(hallcurrent15_t *ctx, float vref)
Hall Current 15 set vref function.
HALLCURRENT15_OK
@ HALLCURRENT15_OK
Definition: hallcurrent15.h:199
hallcurrent15_t::slave_address
uint8_t slave_address
Definition: hallcurrent15.h:165
hallcurrent15_t::adc
analog_in_t adc
Definition: hallcurrent15.h:162
hallcurrent15_cfg_t
Hall Current 15 Click configuration object.
Definition: hallcurrent15.h:177
hallcurrent15_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent15.h:187
hallcurrent15_cfg_t::vref
float vref
Definition: hallcurrent15.h:184
hallcurrent15_write_register
err_t hallcurrent15_write_register(hallcurrent15_t *ctx, uint8_t reg, uint16_t data_in)
Hall Current 15 write register function.
hallcurrent15_t::chip_select
pin_name_t chip_select
Definition: hallcurrent15.h:166
hallcurrent15_cfg_t::drv_sel
hallcurrent15_drv_t drv_sel
Definition: hallcurrent15.h:189
hallcurrent15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent15.h:186
hallcurrent15_read_current
err_t hallcurrent15_read_current(hallcurrent15_t *ctx, float *current)
Hall Current 15 read current function.
hallcurrent15_drv_t
hallcurrent15_drv_t
Hall Current 15 Click driver selector.
Definition: hallcurrent15.h:148
hallcurrent15_read_voltage
err_t hallcurrent15_read_voltage(hallcurrent15_t *ctx, float *voltage)
Hall Current 15 read voltage level function.
HALLCURRENT15_ERROR
@ HALLCURRENT15_ERROR
Definition: hallcurrent15.h:200
hallcurrent15_init
err_t hallcurrent15_init(hallcurrent15_t *ctx, hallcurrent15_cfg_t *cfg)
Hall Current 15 initialization function.
hallcurrent15_cfg_setup
void hallcurrent15_cfg_setup(hallcurrent15_cfg_t *cfg)
Hall Current 15 configuration object setup function.
hallcurrent15_t::i2c
i2c_master_t i2c
Definition: hallcurrent15.h:163
hallcurrent15_t
Hall Current 15 Click context object.
Definition: hallcurrent15.h:159
hallcurrent15_cfg_t::scl
pin_name_t scl
Definition: hallcurrent15.h:179
hallcurrent15_t::drv_sel
hallcurrent15_drv_t drv_sel
Definition: hallcurrent15.h:168
hallcurrent15_cfg_t::alr
pin_name_t alr
Definition: hallcurrent15.h:181
hallcurrent15_t::vref
float vref
Definition: hallcurrent15.h:167
hallcurrent15_drv_interface_selection
void hallcurrent15_drv_interface_selection(hallcurrent15_cfg_t *cfg, hallcurrent15_drv_t drv_sel)
Hall Current 15 driver interface setup function.
hallcurrent15_cfg_t::resolution
analog_in_resolution_t resolution
Definition: hallcurrent15.h:183
hallcurrent15_cfg_t::an
pin_name_t an
Definition: hallcurrent15.h:178