ina2xx.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Eistec AB
3  * 2019 Otto-von-Guericke-Universität Magdeburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
47 #ifndef INA2XX_H
48 #define INA2XX_H
49 
50 #include <stdint.h>
51 
52 #include "periph/i2c.h"
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
61 typedef enum ina2xx_mode {
71 
77 typedef enum ina2xx_sadc {
79  INA2XX_SADC_9BIT = 0x0000,
102 } ina2xx_sadc_t;
103 
109 typedef enum ina2xx_badc {
134 } ina2xx_badc_t;
135 
139 typedef enum ina2xx_pga {
144 } ina2xx_pga_t;
145 
149 typedef enum ina2xx_brng {
152 } ina2xx_brng_t;
153 
164 typedef enum ina2xx_i_range {
172 
176 typedef struct {
178  uint8_t addr;
179  uint16_t config;
180  uint16_t rshunt_mohm;
183 
187 typedef struct {
189 } ina2xx_t;
190 
206 int ina2xx_init(ina2xx_t *dev, const ina2xx_params_t *params);
207 
217 int ina2xx_read_shunt(const ina2xx_t *dev, int16_t *voltage);
218 
231 int ina2xx_read_bus(const ina2xx_t *dev, uint16_t *voltage);
232 
242 int ina2xx_read_current(const ina2xx_t *dev, int32_t *current);
243 
253 int ina2xx_read_power(const ina2xx_t *dev, uint32_t *power);
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif /* INA2XX_H */
260 
INA2XX_BADC_AVG_1_SAMPLE
@ INA2XX_BADC_AVG_1_SAMPLE
12 bit resolution, 532 us conversion time, same as INA2XX_BADC_12BIT
Definition: ina2xx.h:119
INA2XX_SADC_AVG_128_SAMPLES
@ INA2XX_SADC_AVG_128_SAMPLES
128 sample average, 68.10 ms conversion time
Definition: ina2xx.h:101
INA2XX_CURRENT_RANGE_327_MA
@ INA2XX_CURRENT_RANGE_327_MA
±327.68 mA, 0.01mA resolution.
Definition: ina2xx.h:165
INA2XX_BADC_AVG_64_SAMPLES
@ INA2XX_BADC_AVG_64_SAMPLES
64 sample average, 34.05 ms conversion time
Definition: ina2xx.h:131
INA2XX_SADC_10BIT
@ INA2XX_SADC_10BIT
10 bit resolution, 148 us conversion time
Definition: ina2xx.h:81
ina2xx_init
int ina2xx_init(ina2xx_t *dev, const ina2xx_params_t *params)
Initialize a current sensor.
ina2xx_read_bus
int ina2xx_read_bus(const ina2xx_t *dev, uint16_t *voltage)
Read bus voltage in mV.
INA2XX_SADC_AVG_2_SAMPLES
@ INA2XX_SADC_AVG_2_SAMPLES
2 sample average, 1.06 ms conversion time
Definition: ina2xx.h:89
INA2XX_SHUNT_RANGE_80MV
@ INA2XX_SHUNT_RANGE_80MV
+/- 80 mV range
Definition: ina2xx.h:141
INA2XX_BADC_10BIT
@ INA2XX_BADC_10BIT
10 bit resolution, 148 us conversion time
Definition: ina2xx.h:113
ina2xx_read_shunt
int ina2xx_read_shunt(const ina2xx_t *dev, int16_t *voltage)
Read shunt voltage in E-05 V.
INA2XX_MODE_CONTINUOUS_SHUNT_BUS
@ INA2XX_MODE_CONTINUOUS_SHUNT_BUS
Shunt and Bus, Continuous, default.
Definition: ina2xx.h:69
INA2XX_CURRENT_RANGE_1310_MA
@ INA2XX_CURRENT_RANGE_1310_MA
±1310.72 mA, 0.04mA resolution.
Definition: ina2xx.h:167
INA2XX_BADC_AVG_2_SAMPLES
@ INA2XX_BADC_AVG_2_SAMPLES
2 sample average, 1.06 ms conversion time
Definition: ina2xx.h:121
INA2XX_MODE_CONTINUOUS_BUS_ONLY
@ INA2XX_MODE_CONTINUOUS_BUS_ONLY
Bus Voltage, Continuous.
Definition: ina2xx.h:68
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
ina2xx_params_t::rshunt_mohm
uint16_t rshunt_mohm
Size of the shunt resistor in mΩ
Definition: ina2xx.h:180
ina2xx_mode
ina2xx_mode
INA2XX possible mode settings.
Definition: ina2xx.h:61
INA2XX_SADC_AVG_32_SAMPLES
@ INA2XX_SADC_AVG_32_SAMPLES
32 sample average, 17.02 ms conversion time
Definition: ina2xx.h:97
INA2XX_SHUNT_RANGE_320MV
@ INA2XX_SHUNT_RANGE_320MV
+/- 320 mV range, default
Definition: ina2xx.h:143
ina2xx_brng
ina2xx_brng
Bus voltage measurement range.
Definition: ina2xx.h:149
ina2xx_brng_t
enum ina2xx_brng ina2xx_brng_t
Bus voltage measurement range.
INA2XX_BADC_11BIT
@ INA2XX_BADC_11BIT
11 bit resolution, 276 us conversion time
Definition: ina2xx.h:115
ina2xx_read_power
int ina2xx_read_power(const ina2xx_t *dev, uint32_t *power)
Read power consumption in E-04 W.
INA2XX_SADC_AVG_8_SAMPLES
@ INA2XX_SADC_AVG_8_SAMPLES
8 sample average, 4.26 ms conversion time
Definition: ina2xx.h:93
INA2XX_MODE_CONTINUOUS_SHUNT_ONLY
@ INA2XX_MODE_CONTINUOUS_SHUNT_ONLY
Shunt Voltage, Continuous.
Definition: ina2xx.h:67
INA2XX_CURRENT_RANGE_5242_MA
@ INA2XX_CURRENT_RANGE_5242_MA
±5242.88 mA, 0.16mA resolution.
Definition: ina2xx.h:169
ina2xx_t
Device descriptor for INA2XX sensors.
Definition: ina2xx.h:187
ina2xx_params_t::i_range
ina2xx_i_range_t i_range
Range of the measured current.
Definition: ina2xx.h:181
ina2xx_pga_t
enum ina2xx_pga ina2xx_pga_t
Shunt voltage measurement range (PGA settings)
INA2XX_BADC_12BIT
@ INA2XX_BADC_12BIT
12 bit resolution, 532 us conversion time, default
Definition: ina2xx.h:117
INA2XX_BADC_AVG_4_SAMPLES
@ INA2XX_BADC_AVG_4_SAMPLES
4 sample average, 2.13 ms conversion time
Definition: ina2xx.h:123
ina2xx_params_t::addr
uint8_t addr
I2C address of the sensr.
Definition: ina2xx.h:178
INA2XX_MODE_ADC_DISABLE
@ INA2XX_MODE_ADC_DISABLE
ADC Off (disabled)
Definition: ina2xx.h:66
ina2xx_sadc_t
enum ina2xx_sadc ina2xx_sadc_t
Shunt ADC settings.
INA2XX_BUS_RANGE_16V
@ INA2XX_BUS_RANGE_16V
16 V bus voltage full scale range
Definition: ina2xx.h:150
ina2xx_i_range
ina2xx_i_range
Current measurement range.
Definition: ina2xx.h:164
ina2xx_read_current
int ina2xx_read_current(const ina2xx_t *dev, int32_t *current)
Read shunt current in E-05 A.
INA2XX_CURRENT_RANGE_2621_MA
@ INA2XX_CURRENT_RANGE_2621_MA
±2621.44 mA, 0.08mA resolution.
Definition: ina2xx.h:168
INA2XX_MODE_TRIGGER_SHUNT_BUS
@ INA2XX_MODE_TRIGGER_SHUNT_BUS
Shunt and Bus, Triggered.
Definition: ina2xx.h:65
ina2xx_sadc
ina2xx_sadc
Shunt ADC settings.
Definition: ina2xx.h:77
ina2xx_badc
ina2xx_badc
Bus ADC settings.
Definition: ina2xx.h:109
INA2XX_BADC_9BIT
@ INA2XX_BADC_9BIT
9 bit resolution, 84 us conversion time
Definition: ina2xx.h:111
INA2XX_SADC_11BIT
@ INA2XX_SADC_11BIT
11 bit resolution, 276 us conversion time
Definition: ina2xx.h:83
INA2XX_SADC_AVG_64_SAMPLES
@ INA2XX_SADC_AVG_64_SAMPLES
64 sample average, 34.05 ms conversion time
Definition: ina2xx.h:99
INA2XX_MODE_POWERDOWN
@ INA2XX_MODE_POWERDOWN
Power down.
Definition: ina2xx.h:62
ina2xx_t::params
ina2xx_params_t params
Configuration parameters of the driver.
Definition: ina2xx.h:188
ina2xx_badc_t
enum ina2xx_badc ina2xx_badc_t
Bus ADC settings.
INA2XX_CURRENT_RANGE_655_MA
@ INA2XX_CURRENT_RANGE_655_MA
±655.36 mA, 0.02mA resolution.
Definition: ina2xx.h:166
INA2XX_SADC_9BIT
@ INA2XX_SADC_9BIT
9 bit resolution, 84 us conversion time
Definition: ina2xx.h:79
INA2XX_SADC_AVG_16_SAMPLES
@ INA2XX_SADC_AVG_16_SAMPLES
16 sample average, 8.51 ms conversion time
Definition: ina2xx.h:95
INA2XX_MODE_TRIGGER_BUS_ONLY
@ INA2XX_MODE_TRIGGER_BUS_ONLY
Bus Voltage, Triggered.
Definition: ina2xx.h:64
INA2XX_SADC_12BIT
@ INA2XX_SADC_12BIT
12 bit resolution, 532 us conversion time, default
Definition: ina2xx.h:85
INA2XX_SHUNT_RANGE_160MV
@ INA2XX_SHUNT_RANGE_160MV
+/- 160 mV range
Definition: ina2xx.h:142
INA2XX_SHUNT_RANGE_40MV
@ INA2XX_SHUNT_RANGE_40MV
+/- 40 mV range
Definition: ina2xx.h:140
INA2XX_MODE_TRIGGER_SHUNT_ONLY
@ INA2XX_MODE_TRIGGER_SHUNT_ONLY
Shunt Voltage, Triggered.
Definition: ina2xx.h:63
INA2XX_SADC_AVG_4_SAMPLES
@ INA2XX_SADC_AVG_4_SAMPLES
4 sample average, 2.13 ms conversion time
Definition: ina2xx.h:91
INA2XX_SADC_AVG_1_SAMPLE
@ INA2XX_SADC_AVG_1_SAMPLE
12 bit resolution, 532 us conversion time, same as INA2XX_SADC_12BIT
Definition: ina2xx.h:87
ina2xx_params_t::i2c
i2c_t i2c
I2C device the sensor is connected to.
Definition: ina2xx.h:177
INA2XX_BUS_RANGE_32V
@ INA2XX_BUS_RANGE_32V
32 V bus voltage full scale range, default.
Definition: ina2xx.h:151
ina2xx_mode_t
enum ina2xx_mode ina2xx_mode_t
INA2XX possible mode settings.
ina2xx_i_range_t
enum ina2xx_i_range ina2xx_i_range_t
Current measurement range.
INA2XX_BADC_AVG_128_SAMPLES
@ INA2XX_BADC_AVG_128_SAMPLES
128 sample average, 68.10 ms conversion time
Definition: ina2xx.h:133
INA2XX_CURRENT_RANGE_10485_MA
@ INA2XX_CURRENT_RANGE_10485_MA
±10485.76 mA, 0.32mA resolution.
Definition: ina2xx.h:170
INA2XX_BADC_AVG_16_SAMPLES
@ INA2XX_BADC_AVG_16_SAMPLES
16 sample average, 8.51 ms conversion time
Definition: ina2xx.h:127
ina2xx_pga
ina2xx_pga
Shunt voltage measurement range (PGA settings)
Definition: ina2xx.h:139
INA2XX_BADC_AVG_32_SAMPLES
@ INA2XX_BADC_AVG_32_SAMPLES
32 sample average, 17.02 ms conversion time
Definition: ina2xx.h:129
i2c.h
Low-level I2C peripheral driver interface definition.
INA2XX_BADC_AVG_8_SAMPLES
@ INA2XX_BADC_AVG_8_SAMPLES
8 sample average, 4.26 ms conversion time
Definition: ina2xx.h:125
ina2xx_params_t
Configuration parameters of the INA2xx driver.
Definition: ina2xx.h:176
ina2xx_params_t::config
uint16_t config
Configuration to apply.
Definition: ina2xx.h:179