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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 #include "drv_i2c_master.h"
39 
60 #define HALLCURRENT15_REG_CONVERSION_RESULT 0x00
61 #define HALLCURRENT15_REG_ALERT_STATUS 0x01
62 #define HALLCURRENT15_REG_CONFIGURATION 0x02
63 #define HALLCURRENT15_REG_LOW_LIMIT 0x03
64 #define HALLCURRENT15_REG_HIGH_LIMIT 0x04
65 #define HALLCURRENT15_REG_HYSTERESIS 0x05
66 #define HALLCURRENT15_REG_LOWEST_CONVERSION 0x06
67 #define HALLCURRENT15_REG_HIGHEST_CONVERSION 0x07
68  // hallcurrent15_reg
70 
85 #define HALLCURRENT15_SENSITIVITY_V_TO_A 0.05
86 #define HALLCURRENT15_ZERO_CURRENT_OFFSET 0.1
87 #define HALLCURRENT15_NUM_CONVERSIONS 1000
88 
93 #define HALLCURRENT15_ADC_RESOLUTION 0x03FF
94 #define HALLCURRENT15_VREF_3V3 3.3
95 #define HALLCURRENT15_VREF_5V 5.0
96 
102 #define HALLCURRENT15_SET_DEV_ADDR 0x54
103  // hallcurrent15_set
105 
120 #define HALLCURRENT15_MAP_MIKROBUS( cfg, mikrobus ) \
121  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
125  // hallcurrent15_map // hallcurrent15
128 
133 typedef enum
134 {
139 
144 typedef struct
145 {
146  digital_in_t alr;
148  analog_in_t adc;
149  i2c_master_t i2c;
151  uint8_t slave_address;
152  pin_name_t chip_select;
153  float vref;
157 
162 typedef struct
163 {
164  pin_name_t an;
165  pin_name_t scl;
166  pin_name_t sda;
167  pin_name_t alr;
169  analog_in_resolution_t resolution;
170  float vref;
172  uint32_t i2c_speed;
173  uint8_t i2c_address;
178 
183 typedef enum
184 {
187 
189 
206 
222 
237 
250 err_t hallcurrent15_write_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t data_in );
251 
264 err_t hallcurrent15_read_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t *data_out );
265 
275 
287 err_t hallcurrent15_read_raw_adc ( hallcurrent15_t *ctx, uint16_t *raw_adc );
288 
300 err_t hallcurrent15_read_voltage ( hallcurrent15_t *ctx, float *voltage );
301 
313 err_t hallcurrent15_set_vref ( hallcurrent15_t *ctx, float vref );
314 
328 err_t hallcurrent15_read_current ( hallcurrent15_t *ctx, float *current );
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 #endif // HALLCURRENT15_H
334  // hallcurrent15
336 
337 // ------------------------------------------------------------------------ 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:136
hallcurrent15_return_value_t
hallcurrent15_return_value_t
Hall Current 15 Click return value data.
Definition: hallcurrent15.h:184
hallcurrent15_cfg_t::sda
pin_name_t sda
Definition: hallcurrent15.h:166
hallcurrent15_t::alr
digital_in_t alr
Definition: hallcurrent15.h:146
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:135
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:185
hallcurrent15_t::slave_address
uint8_t slave_address
Definition: hallcurrent15.h:151
hallcurrent15_t::adc
analog_in_t adc
Definition: hallcurrent15.h:148
hallcurrent15_cfg_t
Hall Current 15 Click configuration object.
Definition: hallcurrent15.h:163
hallcurrent15_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent15.h:173
hallcurrent15_cfg_t::vref
float vref
Definition: hallcurrent15.h:170
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:152
hallcurrent15_cfg_t::drv_sel
hallcurrent15_drv_t drv_sel
Definition: hallcurrent15.h:175
hallcurrent15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent15.h:172
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:134
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:186
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:149
hallcurrent15_t
Hall Current 15 Click context object.
Definition: hallcurrent15.h:145
hallcurrent15_cfg_t::scl
pin_name_t scl
Definition: hallcurrent15.h:165
hallcurrent15_t::drv_sel
hallcurrent15_drv_t drv_sel
Definition: hallcurrent15.h:154
hallcurrent15_cfg_t::alr
pin_name_t alr
Definition: hallcurrent15.h:167
hallcurrent15_t::vref
float vref
Definition: hallcurrent15.h:153
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:169
hallcurrent15_cfg_t::an
pin_name_t an
Definition: hallcurrent15.h:164