hallcurrent13  2.0.0.0
hallcurrent13.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 HALLCURRENT13_H
29 #define HALLCURRENT13_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 HALLCURRENT13_SENSITIVITY_V_TO_A 0.1
71 #define HALLCURRENT13_ZERO_CURRENT_OFFSET 0.1
72 #define HALLCURRENT13_NUM_CONVERSIONS 100
73 
78 #define HALLCURRENT13_ADC_RESOLUTION 0x0FFF
79 #define HALLCURRENT13_VREF_3V3 3.3
80 #define HALLCURRENT13_VREF_5V 5.0
81 
87 #define HALLCURRENT13_SET_DEV_ADDR 0x4D
88  // hallcurrent13_set
90 
105 #define HALLCURRENT13_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
107  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
108  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
109  // hallcurrent13_map // hallcurrent13
112 
117 typedef enum
118 {
123 
128 typedef struct
129 {
130  analog_in_t adc;
131  i2c_master_t i2c;
133  uint8_t slave_address;
134  pin_name_t chip_select;
135  float vref;
139 
144 typedef struct
145 {
146  pin_name_t an;
147  pin_name_t scl;
148  pin_name_t sda;
150  analog_in_resolution_t resolution;
151  float vref;
153  uint32_t i2c_speed;
154  uint8_t i2c_address;
159 
164 typedef enum
165 {
168 
170 
187 
203 
219 
232 err_t hallcurrent13_read_raw_adc ( hallcurrent13_t *ctx, uint16_t *raw_adc );
233 
246 err_t hallcurrent13_read_voltage ( hallcurrent13_t *ctx, float *voltage );
247 
260 err_t hallcurrent13_set_vref ( hallcurrent13_t *ctx, float vref );
261 
275 err_t hallcurrent13_read_current ( hallcurrent13_t *ctx, float *current );
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 #endif // HALLCURRENT13_H
281  // hallcurrent13
283 
284 // ------------------------------------------------------------------------ END
hallcurrent13_read_voltage
err_t hallcurrent13_read_voltage(hallcurrent13_t *ctx, float *voltage)
Hall Current 13 read voltage level function.
hallcurrent13_drv_interface_selection
void hallcurrent13_drv_interface_selection(hallcurrent13_cfg_t *cfg, hallcurrent13_drv_t drv_sel)
Hall Current 13 driver interface setup function.
hallcurrent13_t::chip_select
pin_name_t chip_select
Definition: hallcurrent13.h:134
hallcurrent13_set_vref
err_t hallcurrent13_set_vref(hallcurrent13_t *ctx, float vref)
Hall Current 13 set vref function.
HALLCURRENT13_ERROR
@ HALLCURRENT13_ERROR
Definition: hallcurrent13.h:167
hallcurrent13_return_value_t
hallcurrent13_return_value_t
Hall Current 13 Click return value data.
Definition: hallcurrent13.h:165
hallcurrent13_t::drv_sel
hallcurrent13_drv_t drv_sel
Definition: hallcurrent13.h:136
hallcurrent13_cfg_t
Hall Current 13 Click configuration object.
Definition: hallcurrent13.h:145
hallcurrent13_cfg_t::scl
pin_name_t scl
Definition: hallcurrent13.h:147
hallcurrent13_init
err_t hallcurrent13_init(hallcurrent13_t *ctx, hallcurrent13_cfg_t *cfg)
Hall Current 13 initialization function.
hallcurrent13_t::i2c
i2c_master_t i2c
Definition: hallcurrent13.h:131
hallcurrent13_cfg_t::drv_sel
hallcurrent13_drv_t drv_sel
Definition: hallcurrent13.h:156
HALLCURRENT13_DRV_SEL_ADC
@ HALLCURRENT13_DRV_SEL_ADC
Definition: hallcurrent13.h:119
hallcurrent13_read_current
err_t hallcurrent13_read_current(hallcurrent13_t *ctx, float *current)
Hall Current 13 read current function.
HALLCURRENT13_OK
@ HALLCURRENT13_OK
Definition: hallcurrent13.h:166
hallcurrent13_drv_t
hallcurrent13_drv_t
Hall Current 13 Click driver selector.
Definition: hallcurrent13.h:118
hallcurrent13_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallcurrent13.h:154
hallcurrent13_t::vref
float vref
Definition: hallcurrent13.h:135
HALLCURRENT13_DRV_SEL_I2C
@ HALLCURRENT13_DRV_SEL_I2C
Definition: hallcurrent13.h:120
hallcurrent13_cfg_t::resolution
analog_in_resolution_t resolution
Definition: hallcurrent13.h:150
hallcurrent13_t::adc
analog_in_t adc
Definition: hallcurrent13.h:130
hallcurrent13_read_raw_adc
err_t hallcurrent13_read_raw_adc(hallcurrent13_t *ctx, uint16_t *raw_adc)
Hall Current 13 read raw ADC value function.
hallcurrent13_cfg_t::sda
pin_name_t sda
Definition: hallcurrent13.h:148
hallcurrent13_cfg_t::vref
float vref
Definition: hallcurrent13.h:151
hallcurrent13_t::slave_address
uint8_t slave_address
Definition: hallcurrent13.h:133
hallcurrent13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallcurrent13.h:153
hallcurrent13_cfg_setup
void hallcurrent13_cfg_setup(hallcurrent13_cfg_t *cfg)
Hall Current 13 configuration object setup function.
hallcurrent13_t
Hall Current 13 Click context object.
Definition: hallcurrent13.h:129
hallcurrent13_cfg_t::an
pin_name_t an
Definition: hallcurrent13.h:146