INA220 current/power monitor¶
Device driver for Texas Instruments INA220 High or Low Side, Bi-Directional CURRENT/POWER MONITOR with Two-Wire Interface.
-
enum
ina220_mode
¶ - INA220_MODE_POWERDOWN
= 0x0000
- Power down.
- INA220_MODE_TRIGGER_SHUNT_ONLY
= 0x0001
- Shunt Voltage, Triggered.
- INA220_MODE_TRIGGER_BUS_ONLY
= 0x0002
- Bus Voltage, Triggered.
- INA220_MODE_TRIGGER_SHUNT_BUS
= 0x0003
- Shunt and Bus, Triggered.
- INA220_MODE_ADC_DISABLE
= 0x0004
- ADC Off (disabled)
- INA220_MODE_CONTINUOUS_SHUNT_ONLY
= 0x0005
- Shunt Voltage, Continuous.
- INA220_MODE_CONTINUOUS_BUS_ONLY
= 0x0006
- Bus Voltage, Continuous.
- INA220_MODE_CONTINUOUS_SHUNT_BUS
= 0x0007
- Shunt and Bus, Continuous, default.
- INA220_MODE_POWERDOWN
-
enum
ina220_range
¶ - INA220_RANGE_40MV
= 0x0000
- +/- 40 mV range
- INA220_RANGE_80MV
= 0x0800
- +/- 80 mV range
- INA220_RANGE_160MV
= 0x1000
- +/- 160 mV range
- INA220_RANGE_320MV
= 0x1800
- +/- 320 mV range, default
- INA220_RANGE_40MV
-
enum
ina220_brng
¶ - INA220_BRNG_16V_FSR
= 0x0000
- 16 V bus voltage full scale range
- INA220_BRNG_32V_FSR
= 0x2000
- 32 V bus voltage full scale range, default.
- INA220_BRNG_16V_FSR
-
enum
ina220_sadc
¶ - INA220_SADC_9BIT
= 0x0000
- 9 bit resolution, 84 us conversion time
- INA220_SADC_10BIT
= 0x0008
- 10 bit resolution, 148 us conversion time
- INA220_SADC_11BIT
= 0x0010
- 11 bit resolution, 276 us conversion time
- INA220_SADC_12BIT
= 0x0018
- 12 bit resolution, 532 us conversion time, default
- INA220_SADC_AVG_1_SAMPLE
= 0x0040
- 12 bit resolution, 532 us conversion time, same as INA220_SADC_12BIT
- INA220_SADC_AVG_2_SAMPLES
= 0x0048
- 2 sample average, 1.06 ms conversion time
- INA220_SADC_AVG_4_SAMPLES
= 0x0050
- 4 sample average, 2.13 ms conversion time
- INA220_SADC_AVG_8_SAMPLES
= 0x0058
- 8 sample average, 4.26 ms conversion time
- INA220_SADC_AVG_16_SAMPLES
= 0x0060
- 16 sample average, 8.51 ms conversion time
- INA220_SADC_AVG_32_SAMPLES
= 0x0068
- 32 sample average, 17.02 ms conversion time
- INA220_SADC_AVG_64_SAMPLES
= 0x0070
- 64 sample average, 34.05 ms conversion time
- INA220_SADC_AVG_128_SAMPLES
= 0x0078
- 128 sample average, 68.10 ms conversion time
- INA220_SADC_9BIT
-
enum
ina220_badc
¶ - INA220_BADC_9BIT
= 0x0000
- 9 bit resolution, 84 us conversion time
- INA220_BADC_10BIT
= 0x0080
- 10 bit resolution, 148 us conversion time
- INA220_BADC_11BIT
= 0x0100
- 11 bit resolution, 276 us conversion time
- INA220_BADC_12BIT
= 0x0180
- 12 bit resolution, 532 us conversion time, default
- INA220_BADC_AVG_1_SAMPLE
= 0x0400
- 12 bit resolution, 532 us conversion time, same as INA220_BADC_12BIT
- INA220_BADC_AVG_2_SAMPLES
= 0x0480
- 2 sample average, 1.06 ms conversion time
- INA220_BADC_AVG_4_SAMPLES
= 0x0500
- 4 sample average, 2.13 ms conversion time
- INA220_BADC_AVG_8_SAMPLES
= 0x0580
- 8 sample average, 4.26 ms conversion time
- INA220_BADC_AVG_16_SAMPLES
= 0x0600
- 16 sample average, 8.51 ms conversion time
- INA220_BADC_AVG_32_SAMPLES
= 0x0680
- 32 sample average, 17.02 ms conversion time
- INA220_BADC_AVG_64_SAMPLES
= 0x0700
- 64 sample average, 34.05 ms conversion time
- INA220_BADC_AVG_128_SAMPLES
= 0x0780
- 128 sample average, 68.10 ms conversion time
- INA220_BADC_9BIT
-
enum
ina220.h::ina220_mode
ina220_mode_t
¶ INA220 possible mode settings.
-
enum
ina220.h::ina220_range
ina220_range_t
¶ Shunt voltage measurement range (PGA settings)
-
enum
ina220.h::ina220_brng
ina220_brng_t
¶ Bus voltage measurement range.
-
enum
ina220.h::ina220_sadc
ina220_sadc_t
¶ Shunt ADC settings.
See also
Table 4 in INA220 data sheet
-
enum
ina220.h::ina220_badc
ina220_badc_t
¶ Bus ADC settings.
See also
Table 4 in INA220 data sheet
-
int
ina220_init
(ina220_t * dev,i2c.h::i2c_t
i2c, uint8_t address)¶ Initialize a current sensor.
Parameters
dev: device descriptor of sensor to initialize i2c: I2C bus the sensor is connected to address: I2C slave address of the sensor Return values
- 0 on success
- <0 on error
-
int
ina220_set_calibration
(const ina220_t * dev, uint16_t calibration)¶ Write to calibration register.
Parameters
dev: device descriptor of sensor to configure calibration: calibration register settings, see data sheet Return values
- 0 on success
- <0 on error
-
int
ina220_set_config
(const ina220_t * dev, uint16_t config)¶ Write to configuration register.
Parameters
dev: device descriptor of sensor to configure config: configuration register settings, see data sheet Return values
- 0 on success
- <0 on error
-
int
ina220_read_shunt
(const ina220_t * dev, int16_t * voltage)¶ Read shunt voltage.
Parameters
dev: device descriptor of sensor voltage: measured voltage across shunt resistor Return values
- 0 on success
- <0 on error
-
int
ina220_read_bus
(const ina220_t * dev, int16_t * voltage)¶ Read bus voltage register.
The bus voltage can be found in the most significant bits of the bus voltage register, the lower three bits are flags/reserved.
See the device data sheet for details.
Parameters
dev: device descriptor of sensor voltage: measured bus voltage Return values
- 0 on success
- <0 on error
-
int
ina220_read_current
(const ina220_t * dev, int16_t * current)¶ Read shunt current.
Parameters
dev: device descriptor of sensor current: measured current through shunt resistor Return values
- 0 on success
- <0 on error
-
int
ina220_read_power
(const ina220_t * dev, int16_t * power)¶ Read power consumption.
Parameters
dev: device descriptor of sensor power: measured power consumption Return values
- 0 on success
- <0 on error
-
INA220_RESET_BIT
¶ INA220 reset command bit (in configuration register)
1
(0x8000)
-
INA220_BUS_VOLTAGE_SHIFT
¶ Location of the bus voltage in the INA220 bus voltage register.
1
(3)
-
struct
ina220_t
¶ Device descriptor for INA220 sensors.
-
i2c.h::i2c_t
i2c
¶ I2C device the sensor is connected to.
-
uint8_t
addr
¶ the slave address of the sensor on the I2C bus
-