current14  2.1.0.0
current14.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 CURRENT14_H
29 #define CURRENT14_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_i2c_master.h"
52 
73 #define CURRENT14_REG_STA1 0x0F
74 #define CURRENT14_REG_DATA_LSB 0x10
75 #define CURRENT14_REG_DATA_MSB 0x11
76 #define CURRENT14_REG_CNTL1 0x1B
77 #define CURRENT14_REG_CNTL2 0x1C
78 #define CURRENT14_REG_CNTL3 0x1D
79 #define CURRENT14_REG_CNTL4_LSB 0x5C
80 #define CURRENT14_REG_CNTL4_MSB 0x5D
81  // current14_reg
83 
98 #define CURRENT14_STA1_RD_DRDY 0x80
99 
104 #define CURRENT14_CNTL1_PC1_POWER_DOWN 0x00
105 #define CURRENT14_CNTL1_PC1_ACTIVE 0x80
106 #define CURRENT14_CNTL1_PC1_MASK 0x80
107 #define CURRENT14_CNTL1_RST_LV_RELEASE 0x00
108 #define CURRENT14_CNTL1_RST_LV_ACTIVE 0x20
109 #define CURRENT14_CNTL1_RST_LV_MASK 0x20
110 #define CURRENT14_CNTL1_ODR_20_HZ 0x00
111 #define CURRENT14_CNTL1_ODR_100_HZ 0x08
112 #define CURRENT14_CNTL1_ODR_200_HZ 0x10
113 #define CURRENT14_CNTL1_ODR_1_KHZ 0x18
114 #define CURRENT14_CNTL1_ODR_MASK 0x18
115 #define CURRENT14_CNTL1_FS1_CONTINUOUS 0x00
116 #define CURRENT14_CNTL1_FS1_SINGLE 0x02
117 #define CURRENT14_CNTL1_FS1_MASK 0x02
118 
123 #define CURRENT14_CNTL2_ALERT_EN 0x08
124 
129 #define CURRENT14_CNTL3_FORCE 0x40
130 
135 #define CURRENT14_CNTL4_RELEASE 0x0000
136 
141 #define CURRENT14_ODR_20_HZ 0
142 #define CURRENT14_ODR_100_HZ 1
143 #define CURRENT14_ODR_200_HZ 2
144 #define CURRENT14_ODR_1_KHZ 3
145 
150 #define CURRENT14_TIMEOUT_MS 2000
151 
157 #define CURRENT14_DEVICE_ADDRESS_0 0x0E
158 #define CURRENT14_DEVICE_ADDRESS_1 0x0F
159  // current14_set
161 
176 #define CURRENT14_MAP_MIKROBUS( cfg, mikrobus ) \
177  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
178  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
179  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
180  // current14_map // current14
183 
188 typedef struct
189 {
190  // Input pins
191  digital_in_t alert;
193  // Modules
194  i2c_master_t i2c;
196  // I2C slave address
197  uint8_t slave_address;
201  uint16_t odr;
203 } current14_t;
204 
209 typedef struct
210 {
211  pin_name_t scl;
212  pin_name_t sda;
214  pin_name_t alert;
216  uint32_t i2c_speed;
217  uint8_t i2c_address;
220 
225 typedef enum
226 {
228  CURRENT14_ERROR = -1
229 
231 
248 
263 
277 
290 err_t current14_write_reg_byte ( current14_t *ctx, uint8_t reg, uint8_t data_in );
291 
304 err_t current14_write_reg_word ( current14_t *ctx, uint8_t reg, uint16_t data_in );
305 
318 err_t current14_read_reg_byte ( current14_t *ctx, uint8_t reg, uint8_t *data_out );
319 
329 
344 err_t current14_set_odr ( current14_t *ctx, uint8_t odr );
345 
357 err_t current14_read_data ( current14_t *ctx, int16_t *data_out );
358 
370 
383 err_t current14_calib_resolution ( current14_t *ctx, float calib_current );
384 
397 err_t current14_get_current ( current14_t *ctx, float *current );
398 
399 #ifdef __cplusplus
400 }
401 #endif
402 #endif // CURRENT14_H
403  // current14
405 
406 // ------------------------------------------------------------------------ END
current14_calib_resolution
err_t current14_calib_resolution(current14_t *ctx, float calib_current)
Current 14 calib resolution function.
current14_t::odr
uint16_t odr
Definition: current14.h:201
current14_cfg_t
Current 14 Click configuration object.
Definition: current14.h:210
current14_t::zero_curr_offset
float zero_curr_offset
Definition: current14.h:199
current14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: current14.h:216
current14_t::slave_address
uint8_t slave_address
Definition: current14.h:197
current14_t::alert
digital_in_t alert
Definition: current14.h:191
current14_cfg_t::sda
pin_name_t sda
Definition: current14.h:212
current14_init
err_t current14_init(current14_t *ctx, current14_cfg_t *cfg)
Current 14 initialization function.
current14_cfg_t::alert
pin_name_t alert
Definition: current14.h:214
current14_write_reg_word
err_t current14_write_reg_word(current14_t *ctx, uint8_t reg, uint16_t data_in)
Current 14 write reg word function.
current14_write_reg_byte
err_t current14_write_reg_byte(current14_t *ctx, uint8_t reg, uint8_t data_in)
Current 14 write reg byte function.
current14_set_odr
err_t current14_set_odr(current14_t *ctx, uint8_t odr)
Current 14 set odr function.
CURRENT14_OK
@ CURRENT14_OK
Definition: current14.h:227
CURRENT14_ERROR
@ CURRENT14_ERROR
Definition: current14.h:228
current14_t
Current 14 Click context object.
Definition: current14.h:189
current14_read_data
err_t current14_read_data(current14_t *ctx, int16_t *data_out)
Current 14 read data function.
current14_get_current
err_t current14_get_current(current14_t *ctx, float *current)
Current 14 get current function.
current14_get_alert_pin
uint8_t current14_get_alert_pin(current14_t *ctx)
Current 14 get alert pin function.
current14_cfg_setup
void current14_cfg_setup(current14_cfg_t *cfg)
Current 14 configuration object setup function.
current14_calib_offset
err_t current14_calib_offset(current14_t *ctx)
Current 14 calib offset function.
current14_t::data_resolution
float data_resolution
Definition: current14.h:200
current14_default_cfg
err_t current14_default_cfg(current14_t *ctx)
Current 14 default configuration function.
current14_read_reg_byte
err_t current14_read_reg_byte(current14_t *ctx, uint8_t reg, uint8_t *data_out)
Current 14 read reg byte function.
current14_cfg_t::scl
pin_name_t scl
Definition: current14.h:211
current14_t::i2c
i2c_master_t i2c
Definition: current14.h:194
current14_return_value_t
current14_return_value_t
Current 14 Click return value data.
Definition: current14.h:226
current14_cfg_t::i2c_address
uint8_t i2c_address
Definition: current14.h:217