current6  2.0.0.0
current6.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 CURRENT6_H
29 #define CURRENT6_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_i2c_master.h"
48 
69 #define CURRENT6_REG_CONFIGURATION 0x00
70 #define CURRENT6_REG_STATUS 0x02
71 #define CURRENT6_REG_THRESHOLD_OVER_CURRENT 0x04
72 #define CURRENT6_REG_THRESHOLD_OVER_VOLTAGE 0x05
73 #define CURRENT6_REG_THRESHOLD_UNDER_VOLTAGE 0x06
74 #define CURRENT6_REG_WAKE_UP_CURRENT 0x07
75 #define CURRENT6_REG_MAX_PEAK_CURRENT 0x08
76 #define CURRENT6_REG_FIFO_CONFIGURATION 0x0A
77 #define CURRENT6_REG_CURRENT_MEASUREMENT 0x0C
78 #define CURRENT6_REG_VOLTAGE_MEASUREMENT 0x0E
79 #define CURRENT6_REG_CURRENT_VOLTAGE_MEASUREMENT 0x10
80 #define CURRENT6_REG_INT_EN 0x14
81  // current6_reg
83 
98 #define CURRENT6_OPMODE_STANDBY 0x0000
99 #define CURRENT6_OPMODE_LOW_POWER 0x0001
100 #define CURRENT6_OPMODE_SINGLE_CONVERSION 0x0002
101 #define CURRENT6_OPMODE_CONTINUOUS_MEASUREMENT 0x0003
102 #define CURRENT6_OPMODE_ACTIVE_MODE_4_SPS 0x0004
103 #define CURRENT6_OPMODE_ACTIVE_MODE_1_SPS 0x0005
104 #define CURRENT6_OPMODE_ACTIVE_MODE_0p25_SPS 0x0006
105 #define CURRENT6_OPMODE_ACTIVE_MODE_0p0625_SPS 0x0007
106 #define CURRENT6_OPMODE_ACTIVE_MODE_0p25_SPS 0x0006
107 #define CURRENT6_I2C_TIMEOUT_DISABLE 0x0008
108 #define CURRENT6_I2C_TIMEOUT_ENABLE 0x0000
109 #define CURRENT6_ALERT_UNFILTERED 0x0000
110 #define CURRENT6_ALERT_FILTERED 0x0010
111 #define CURRENT6_PEC_ENABLE 0x0020
112 #define CURRENT6_PEC_DISABLE 0x0000
113 #define CURRENT6_INPUT_RANGE_10mV 0x0040
114 #define CURRENT6_INPUT_RANGE_50mV 0x0000
115 #define CURRENT6_ENTER_HS_MODE 0x0080
116 #define CURRENT6_EXIT_HS_MODE 0x0000
117 #define CURRENT6_ADC_SAMPLE_RATE_15_KSPS 0x0000
118 #define CURRENT6_ADC_SAMPLE_RATE_23p45_KSPS 0x0200
119 #define CURRENT6_ADC_SAMPLE_RATE_30_KSPS 0x0300
120 #define CURRENT6_ADC_SAMPLE_RATE_37p5_KSPS 0x0400
121 #define CURRENT6_ADC_SAMPLE_RATE_47p1_KSPS 0x0500
122 #define CURRENT6_ADC_SAMPLE_RATE_60_KSPS 0x0600
123 #define CURRENT6_ADC_SAMPLE_RATE_93p5_KSPS 0x0700
124 #define CURRENT6_ADC_SAMPLE_RATE_120_KSPS 0x0800
125 #define CURRENT6_ADC_SAMPLE_RATE_150_KSPS 0x0900
126 #define CURRENT6_ADC_SAMPLE_RATE_234p5_KSPS 0x0A00
127 #define CURRENT6_ADC_SAMPLE_RATE_375_KSPS 0x0B00
128 #define CURRENT6_ADC_SAMPLE_RATE_468p5_KSPS 0x0C00
129 #define CURRENT6_ADC_SAMPLE_RATE_750_KSPS 0x0D00
130 #define CURRENT6_ADC_SAMPLE_RATE_1000_KSPS 0x0E00
131 #define CURRENT6_ADC_SAMPLE_RATE_0p5_KSPS 0x0F00
132 #define CURRENT6_DIGITAL_FILTER_NO_AVG 0x0000
133 #define CURRENT6_DIGITAL_FILTER_AVG_8_SAMPLES 0x1000
134 #define CURRENT6_DIGITAL_FILTER_AVG_16_SAMPLES 0x2000
135 #define CURRENT6_DIGITAL_FILTER_AVG_32_SAMPLES 0x3000
136 #define CURRENT6_DIGITAL_FILTER_AVG_64_SAMPLES 0x4000
137 #define CURRENT6_DIGITAL_FILTER_AVG_128_SAMPLES 0x5000
138 
143 #define CURRENT6_STATUS_WAKE_UP 0x0001
144 #define CURRENT6_STATUS_CONVERSION_READY 0x0002
145 #define CURRENT6_STATUS_OVERFLOW_CURRENT 0x0004
146 #define CURRENT6_STATUS_OVERFLOW_VOLTAGE 0x0008
147 #define CURRENT6_STATUS_UNDERFLOW_VOLTAGE 0x0010
148 #define CURRENT6_STATUS_I2C_TIMEOUT 0x0020
149 #define CURRENT6_STATUS_FIFO_ALARM 0x0040
150 #define CURRENT6_STATUS_FIFO_OVERFLOW 0x0080
151 #define CURRENT6_STATUS_FIFO_DATA_COUNT_MASK 0x3F00
152 
157 #define CURRENT6_FIFO_CFG_STORE_CURRENT_ONLY 0x0000
158 #define CURRENT6_FIFO_CFG_STORE_VOLTAGE_ONLY 0x0001
159 #define CURRENT6_FIFO_CFG_STORE_ALL 0x0002
160 #define CURRENT6_FIFO_CFG_DATA_OVERFLOW_MASK 0x3F00
161 #define CURRENT6_FIFO_CFG_DATA_OVERFLOW_DEFAULT 0x0100
162 #define CURRENT6_FIFO_CFG_ROLL_OVER 0x4000
163 #define CURRENT6_FIFO_CFG_FLUSH 0x8000
164 
169 #define CURRENT6_FIFO_DATA_VALID_32 0x80000000
170 #define CURRENT6_FIFO_DATA_VALID_16 0x8000
171 #define CURRENT6_FIFO_DATA_SIGN_BIT 0x1000
172 #define CURRENT6_FIFO_DATA_RESOLUTION 0x0FFF
173 
178 #define CURRENT6_INT_EN_WAKE_UP 0x01
179 #define CURRENT6_INT_EN_CONVERSION_READY 0x02
180 #define CURRENT6_INT_EN_OVERFLOW_CURRENT 0x04
181 #define CURRENT6_INT_EN_OVERFLOW_VOLTAGE 0x08
182 #define CURRENT6_INT_EN_UNDERFLOW_VOLTAGE 0x10
183 #define CURRENT6_INT_EN_I2C_TIMEOUT 0x20
184 #define CURRENT6_INT_EN_ALARM 0x40
185 #define CURRENT6_INT_EN_OVERFLOW 0x80
186 
191 #define CURRENT6_VOLTAGE_CALCULATION_COEFFICIENT 0.00917
192 #define CURRENT6_CURRENT_CALCULATION_COEFFICIENT 0.00125
193 
199 #define CURRENT6_SET_DEV_ADDR 0x21
200  // current6_set
202 
217 #define CURRENT6_MAP_MIKROBUS( cfg, mikrobus ) \
218  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
219  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
220  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
221  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
222  // current6_map // current6
225 
230 typedef struct
231 {
232  // Output pins
233  digital_out_t en;
235  // Input pins
236  digital_in_t alr;
238  // Modules
239  i2c_master_t i2c;
241  // I2C slave address
242  uint8_t slave_address;
244  uint8_t pec_enable;
246 } current6_t;
247 
252 typedef struct
253 {
254  pin_name_t scl;
255  pin_name_t sda;
257  pin_name_t alr;
258  pin_name_t en;
260  uint32_t i2c_speed;
261  uint8_t i2c_address;
264 
269 typedef enum
270 {
272  CURRENT6_ERROR = -1
273 
275 
292 
308 
323 
338 err_t current6_write_byte ( current6_t *ctx, uint8_t reg, uint8_t data_in );
339 
354 err_t current6_read_byte ( current6_t *ctx, uint8_t reg, uint8_t *data_out );
355 
370 err_t current6_write_word ( current6_t *ctx, uint8_t reg, uint16_t data_in );
371 
386 err_t current6_read_word ( current6_t *ctx, uint8_t reg, uint16_t *data_out );
387 
401 err_t current6_read_32 ( current6_t *ctx, uint32_t *data_out );
402 
412 
426 err_t current6_read_data ( current6_t *ctx, float *voltage, float *current );
427 
440 err_t current6_get_status ( current6_t *ctx, uint16_t *status );
441 
452 
463 
473 
483 
484 #ifdef __cplusplus
485 }
486 #endif
487 #endif // CURRENT6_H
488  // current6
490 
491 // ------------------------------------------------------------------------ END
current6_cfg_t::i2c_address
uint8_t i2c_address
Definition: current6.h:261
current6_enable_device
void current6_enable_device(current6_t *ctx)
Current 6 enable device function.
current6_enable_pec
err_t current6_enable_pec(current6_t *ctx)
PEC Enable function.
CURRENT6_OK
@ CURRENT6_OK
Definition: current6.h:271
current6_t::slave_address
uint8_t slave_address
Definition: current6.h:242
current6_t::en
digital_out_t en
Definition: current6.h:233
current6_cfg_t
Current 6 Click configuration object.
Definition: current6.h:253
current6_read_byte
err_t current6_read_byte(current6_t *ctx, uint8_t reg, uint8_t *data_out)
Current 6 read byte function.
current6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: current6.h:260
current6_cfg_t::en
pin_name_t en
Definition: current6.h:258
current6_write_word
err_t current6_write_word(current6_t *ctx, uint8_t reg, uint16_t data_in)
Current 6 write word function.
current6_write_byte
err_t current6_write_byte(current6_t *ctx, uint8_t reg, uint8_t data_in)
Current 6 write byte function.
current6_t::i2c
i2c_master_t i2c
Definition: current6.h:239
current6_t::pec_enable
uint8_t pec_enable
Definition: current6.h:244
current6_cfg_t::sda
pin_name_t sda
Definition: current6.h:255
current6_t::alr
digital_in_t alr
Definition: current6.h:236
current6_cfg_t::scl
pin_name_t scl
Definition: current6.h:254
current6_read_data
err_t current6_read_data(current6_t *ctx, float *voltage, float *current)
Current 6 read data function.
current6_cfg_t::alr
pin_name_t alr
Definition: current6.h:257
current6_return_value_t
current6_return_value_t
Current 6 Click return value data.
Definition: current6.h:270
current6_disable_pec
err_t current6_disable_pec(current6_t *ctx)
PEC Disable function.
current6_read_32
err_t current6_read_32(current6_t *ctx, uint32_t *data_out)
Current 6 read 32-bit function.
current6_init
err_t current6_init(current6_t *ctx, current6_cfg_t *cfg)
Current 6 initialization function.
current6_cfg_setup
void current6_cfg_setup(current6_cfg_t *cfg)
Current 6 configuration object setup function.
current6_read_word
err_t current6_read_word(current6_t *ctx, uint8_t reg, uint16_t *data_out)
Current 6 read word function.
current6_t
Current 6 Click context object.
Definition: current6.h:231
current6_default_cfg
err_t current6_default_cfg(current6_t *ctx)
Current 6 default configuration function.
current6_get_status
err_t current6_get_status(current6_t *ctx, uint16_t *status)
Current 6 get status function.
current6_get_alert_pin
uint8_t current6_get_alert_pin(current6_t *ctx)
Current 6 get alert pin function.
current6_disable_device
void current6_disable_device(current6_t *ctx)
Current 6 disable device function.
CURRENT6_ERROR
@ CURRENT6_ERROR
Definition: current6.h:272