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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_analog_in.h"
48 #include "drv_i2c_master.h"
49 
70 #define HALLCURRENT15_REG_CONVERSION_RESULT 0x00
71 #define HALLCURRENT15_REG_ALERT_STATUS 0x01
72 #define HALLCURRENT15_REG_CONFIGURATION 0x02
73 #define HALLCURRENT15_REG_LOW_LIMIT 0x03
74 #define HALLCURRENT15_REG_HIGH_LIMIT 0x04
75 #define HALLCURRENT15_REG_HYSTERESIS 0x05
76 #define HALLCURRENT15_REG_LOWEST_CONVERSION 0x06
77 #define HALLCURRENT15_REG_HIGHEST_CONVERSION 0x07
78  // hallcurrent15_reg
80 
95 #define HALLCURRENT15_SENSITIVITY_V_TO_A 0.05
96 #define HALLCURRENT15_ZERO_CURRENT_OFFSET 0.1
97 #define HALLCURRENT15_NUM_CONVERSIONS 1000
98 
103 #define HALLCURRENT15_ADC_RESOLUTION 0x03FF
104 #define HALLCURRENT15_VREF_3V3 3.3
105 #define HALLCURRENT15_VREF_5V 5.0
106 
112 #define HALLCURRENT15_SET_DEV_ADDR 0x54
113  // hallcurrent15_set
115 
130 #define HALLCURRENT15_MAP_MIKROBUS( cfg, mikrobus ) \
131  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
132  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
133  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
134  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
135  // hallcurrent15_map // hallcurrent15
138 
143 typedef enum
144 {
149 
154 typedef struct
155 {
156  digital_in_t alr;
158  analog_in_t adc;
159  i2c_master_t i2c;
161  uint8_t slave_address;
162  pin_name_t chip_select;
163  float vref;
167 
172 typedef struct
173 {
174  pin_name_t an;
175  pin_name_t scl;
176  pin_name_t sda;
177  pin_name_t alr;
179  analog_in_resolution_t resolution;
180  float vref;
182  uint32_t i2c_speed;
183  uint8_t i2c_address;
188 
193 typedef enum
194 {
197 
199 
216 
232 
247 
260 err_t hallcurrent15_write_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t data_in );
261 
274 err_t hallcurrent15_read_register ( hallcurrent15_t *ctx, uint8_t reg, uint16_t *data_out );
275 
285 
297 err_t hallcurrent15_read_raw_adc ( hallcurrent15_t *ctx, uint16_t *raw_adc );
298 
310 err_t hallcurrent15_read_voltage ( hallcurrent15_t *ctx, float *voltage );
311 
323 err_t hallcurrent15_set_vref ( hallcurrent15_t *ctx, float vref );
324 
338 err_t hallcurrent15_read_current ( hallcurrent15_t *ctx, float *current );
339 
340 #ifdef __cplusplus
341 }
342 #endif
343 #endif // HALLCURRENT15_H
344  // hallcurrent15
346 
347 // ------------------------------------------------------------------------ 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:146
hallcurrent15_return_value_t
hallcurrent15_return_value_t
Hall Current 15 Click return value data.
Definition: hallcurrent15.h:194
hallcurrent15_cfg_t::sda
pin_name_t sda
Definition: hallcurrent15.h:176
hallcurrent15_t::alr
digital_in_t alr
Definition: hallcurrent15.h:156
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:145
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:195
hallcurrent15_t::slave_address
uint8_t slave_address
Definition: hallcurrent15.h:161
hallcurrent15_t::adc
analog_in_t adc
Definition: hallcurrent15.h:158
hallcurrent15_cfg_t
Hall Current 15 Click configuration object.
Definition: hallcurrent15.h:173
hallcurrent15_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent15.h:183
hallcurrent15_cfg_t::vref
float vref
Definition: hallcurrent15.h:180
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:162
hallcurrent15_cfg_t::drv_sel
hallcurrent15_drv_t drv_sel
Definition: hallcurrent15.h:185
hallcurrent15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent15.h:182
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:144
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:196
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:159
hallcurrent15_t
Hall Current 15 Click context object.
Definition: hallcurrent15.h:155
hallcurrent15_cfg_t::scl
pin_name_t scl
Definition: hallcurrent15.h:175
hallcurrent15_t::drv_sel
hallcurrent15_drv_t drv_sel
Definition: hallcurrent15.h:164
hallcurrent15_cfg_t::alr
pin_name_t alr
Definition: hallcurrent15.h:177
hallcurrent15_t::vref
float vref
Definition: hallcurrent15.h:163
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:179
hallcurrent15_cfg_t::an
pin_name_t an
Definition: hallcurrent15.h:174