current9 2.1.0.0
current9.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 CURRENT9_H
29#define CURRENT9_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 CURRENT9_SENSITIVITY_V_TO_A 0.1333
75#define CURRENT9_ZERO_CURRENT_OFFSET 0.500
76#define CURRENT9_NUM_CONVERSIONS 200
77#define CURRENT9_SENSOR_OUT_DIVIDER_2 2.0
78#define CURRENT9_90PCT_VCC 4.5
79
84#define CURRENT9_ADC_RESOLUTION 0x0FFF
85#define CURRENT9_VREF_3V3 3.3
86#define CURRENT9_VREF_5V 5.0
87
93#define CURRENT9_SET_DEV_ADDR 0x4D
94
95 // current9_set
96
111#define CURRENT9_MAP_MIKROBUS( cfg, mikrobus ) \
112 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
113 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
114 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
115
116 // current9_map
117 // current9
118
129
134typedef struct
135{
136 analog_in_t adc;
137 i2c_master_t i2c;
140 pin_name_t chip_select;
141 float vref;
144} current9_t;
145
150typedef struct
151{
152 pin_name_t an;
153 pin_name_t scl;
154 pin_name_t sda;
156 analog_in_resolution_t resolution;
157 float vref;
159 uint32_t i2c_speed;
160 uint8_t i2c_address;
165
170typedef enum
171{
173 CURRENT9_ERROR = -1
174
176
193
209
224
236err_t current9_read_raw_adc ( current9_t *ctx, uint16_t *raw_adc );
237
249err_t current9_read_voltage ( current9_t *ctx, float *voltage );
250
262err_t current9_set_vref ( current9_t *ctx, float vref );
263
278err_t current9_read_current ( current9_t *ctx, float *current );
279
280#ifdef __cplusplus
281}
282#endif
283#endif // CURRENT9_H
284
285 // current9
286
287// ------------------------------------------------------------------------ END
current9_drv_t
Current 9 Click driver selector.
Definition current9.h:124
@ CURRENT9_DRV_SEL_I2C
Definition current9.h:126
@ CURRENT9_DRV_SEL_ADC
Definition current9.h:125
current9_return_value_t
Current 9 Click return value data.
Definition current9.h:171
@ CURRENT9_ERROR
Definition current9.h:173
@ CURRENT9_OK
Definition current9.h:172
void current9_cfg_setup(current9_cfg_t *cfg)
Current 9 configuration object setup function.
err_t current9_init(current9_t *ctx, current9_cfg_t *cfg)
Current 9 initialization function.
err_t current9_set_vref(current9_t *ctx, float vref)
Current 9 set vref function.
err_t current9_read_current(current9_t *ctx, float *current)
Current 9 read current function.
err_t current9_read_raw_adc(current9_t *ctx, uint16_t *raw_adc)
Current 9 read raw ADC value function.
void current9_drv_interface_selection(current9_cfg_t *cfg, current9_drv_t drv_sel)
Current 9 driver interface setup function.
err_t current9_read_voltage(current9_t *ctx, float *voltage)
Current 9 read voltage level function.
Current 9 Click configuration object.
Definition current9.h:151
analog_in_resolution_t resolution
Definition current9.h:156
float vref
Definition current9.h:157
uint32_t i2c_speed
Definition current9.h:159
pin_name_t scl
Definition current9.h:153
pin_name_t sda
Definition current9.h:154
pin_name_t an
Definition current9.h:152
current9_drv_t drv_sel
Definition current9.h:162
uint8_t i2c_address
Definition current9.h:160
Current 9 Click context object.
Definition current9.h:135
float vref
Definition current9.h:141
i2c_master_t i2c
Definition current9.h:137
uint8_t slave_address
Definition current9.h:139
pin_name_t chip_select
Definition current9.h:140
analog_in_t adc
Definition current9.h:136
current9_drv_t drv_sel
Definition current9.h:142