RegForge

All parts / INA219

INA219 register map

High-side bidirectional current and power monitor with I2C — Texas Instruments

6 registers I2C I²C 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F 8-bit reg addresses 94% bit coverage not yet human-verified
I²C address conflict. On its default address(es) this part collides with ADS1115 (0x48, 0x49, 0x4A, 0x4B); INA226 (0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F); PCA9685 (0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F). You cannot put them on the same bus without changing a strap pin, using an I²C multiplexer, or moving one to a second bus. See the full address map.

Get it as a C header

pip install regforge
regforge gen INA219 --out ./src --driver --tests

Writes ina219_regs.h with every address, mask and shift below, a bus-agnostic driver skeleton, and a file of compile-time assertions that make your compiler check the bit arithmetic. No API key needed — this part ships inside the package.

Not yet human-verified. Transcribed and mechanically validated — no overlapping fields, no out-of-range bits, reset values consistent with their fields — but not yet checked line-by-line against the datasheet. Verifying it is a useful half hour.

Registers

AddrRegisterAccessWidthResetDescription
0x00CONFIGRW160x399FBus voltage range, PGA gain, ADC resolution/averaging and operating mode
0x01SHUNT_VOLTAGERO16—Measured shunt voltage, two's complement. LSB weight depends on the PG setting.
0x02BUS_VOLTAGERO16—Measured bus voltage, plus conversion-ready and overflow flags
0x03POWERRO160x0000Calculated power. Reads zero until CALIBRATION has been written.
0x04CURRENTRO160x0000Calculated current, two's complement. Reads zero until CALIBRATION has been written.
0x05CALIBRATIONRW160x0000Current/power scaling. Bit 0 is not used; the value is effectively 15-bit.

Bit layouts

Drawn MSB-first, the way the datasheet draws them. [7:5] means shift 5, width 3, mask 0xE0 — this is the notation that costs people a day when they read it backwards.

CONFIG  @  0x00  —  6 fields
RST[15]
—14
BRNG[13]
PG[12:11]
BADC[10:7]
SADC[6:3]
MODE[2:0]
BitsFieldAccessMaskResetDescription
[15]RSTW1P0x80000x00Write 1 to reset all registers to their default values; self-clearing
[13]BRNGRW0x20000x01Bus voltage range
[12:11]PGRW0x18000x03Shunt voltage PGA gain and range
[10:7]BADCRW0x07800x03Bus ADC resolution and averaging
[6:3]SADCRW0x00780x03Shunt ADC resolution and averaging
[2:0]MODERW0x00070x07Operating mode

CONFIG.BRNG values

ValueNameMeaning
0x00FSR_16V16 V full scale
0x01FSR_32V32 V full scale (default)

CONFIG.PG values

ValueNameMeaning
0x00GAIN_1_40MVGain /1, +/-40 mV
0x01GAIN_2_80MVGain /2, +/-80 mV
0x02GAIN_4_160MVGain /4, +/-160 mV
0x03GAIN_8_320MVGain /8, +/-320 mV (default)

CONFIG.BADC values

ValueNameMeaning
0x00RES_9BIT9-bit, 84 us
0x01RES_10BIT10-bit, 148 us
0x02RES_11BIT11-bit, 276 us
0x03RES_12BIT12-bit, 532 us (default)
0x09SAMPLES_212-bit, 2 samples averaged, 1.06 ms
0x0ASAMPLES_412-bit, 4 samples averaged, 2.13 ms
0x0BSAMPLES_812-bit, 8 samples averaged, 4.26 ms
0x0CSAMPLES_1612-bit, 16 samples averaged, 8.51 ms
0x0DSAMPLES_3212-bit, 32 samples averaged, 17.02 ms
0x0ESAMPLES_6412-bit, 64 samples averaged, 34.05 ms
0x0FSAMPLES_12812-bit, 128 samples averaged, 68.10 ms

CONFIG.SADC values

ValueNameMeaning
0x00RES_9BIT9-bit, 84 us
0x01RES_10BIT10-bit, 148 us
0x02RES_11BIT11-bit, 276 us
0x03RES_12BIT12-bit, 532 us (default)
0x09SAMPLES_212-bit, 2 samples averaged, 1.06 ms
0x0ASAMPLES_412-bit, 4 samples averaged, 2.13 ms
0x0BSAMPLES_812-bit, 8 samples averaged, 4.26 ms
0x0CSAMPLES_1612-bit, 16 samples averaged, 8.51 ms
0x0DSAMPLES_3212-bit, 32 samples averaged, 17.02 ms
0x0ESAMPLES_6412-bit, 64 samples averaged, 34.05 ms
0x0FSAMPLES_12812-bit, 128 samples averaged, 68.10 ms

CONFIG.MODE values

ValueNameMeaning
0x00POWER_DOWNPower down
0x01SHUNT_TRIGGEREDShunt voltage, triggered
0x02BUS_TRIGGEREDBus voltage, triggered
0x03SHUNT_BUS_TRIGGEREDShunt and bus, triggered
0x04ADC_OFFADC off / disabled
0x05SHUNT_CONTINUOUSShunt voltage, continuous
0x06BUS_CONTINUOUSBus voltage, continuous
0x07SHUNT_BUS_CONTINUOUSShunt and bus, continuous (default)
BUS_VOLTAGE  @  0x02  —  3 fields
BD[15:3]
—2
CNVR[1]
OVF[0]
BitsFieldAccessMaskResetDescription
[15:3]BDRO0xFFF8—Bus voltage data, 4 mV per LSB
[1]CNVRRO0x0002—Conversion ready; cleared by reading the POWER register or writing CONFIG
[0]OVFRO0x0001—Math overflow: the power or current calculation was out of range

Generated C header

What regforge gen INA219 writes for CONFIG:

/* ------------------------------------------------------------------------ */
/* CONFIG @ 0x00u  rw  16-bit  reset 0x399Fu */
/* Bus voltage range, PGA gain, ADC resolution/averaging and operating mode */
/* ------------------------------------------------------------------------ */

#define INA219_CONFIG                                  0x00u
#define INA219_CONFIG_WIDTH                            16u
#define INA219_CONFIG_RESET                            0x399Fu

/*   RST bits [15] w1p reset 0x00u -- Write 1 to reset all registers to their default values; self-clearing */
#define INA219_CONFIG_RST_SHIFT                        15u
#define INA219_CONFIG_RST_WIDTH                        1u
#define INA219_CONFIG_RST_MASK                         0x8000u
#define INA219_CONFIG_RST_GET(reg)                     (((uint16_t)(reg) & 0x8000u) >> 15u)
#define INA219_CONFIG_RST_SET(reg, val)                (((uint16_t)(reg) & (uint16_t)~0x8000u) | (((uint16_t)(val) << 15u) & 0x8000u))

/*   BRNG bits [13] rw reset 0x01u -- Bus voltage range */
#define INA219_CONFIG_BRNG_SHIFT                       13u
#define INA219_CONFIG_BRNG_WIDTH                       1u
#define INA219_CONFIG_BRNG_MASK                        0x2000u
#define INA219_CONFIG_BRNG_GET(reg)                    (((uint16_t)(reg) & 0x2000u) >> 13u)
#define INA219_CONFIG_BRNG_SET(reg, val)               (((uint16_t)(reg) & (uint16_t)~0x2000u) | (((uint16_t)(val) << 13u) & 0x2000u))
#define INA219_CONFIG_BRNG_FSR_16V                     0x00u  /* 16 V full scale */
#define INA219_CONFIG_BRNG_FSR_32V                     0x01u  /* 32 V full scale (default) */

/*   PG bits [12:11] rw reset 0x03u -- Shunt voltage PGA gain and range */
#define INA219_CONFIG_PG_SHIFT                         11u
#define INA219_CONFIG_PG_WIDTH                         2u
#define INA219_CONFIG_PG_MASK                          0x1800u
#define INA219_CONFIG_PG_GET(reg)                      (((uint16_t)(reg) & 0x1800u) >> 11u)
#define INA219_CONFIG_PG_SET(reg, val)                 (((uint16_t)(reg) & (uint16_t)~0x1800u) | (((uint16_t)(val) << 11u) & 0x1800u))
#define INA219_CONFIG_PG_GAIN_1_40MV                   0x00u  /* Gain /1, +/-40 mV */
#define INA219_CONFIG_PG_GAIN_2_80MV                   0x01u  /* Gain /2, +/-80 mV */
#define INA219_CONFIG_PG_GAIN_4_160MV                  0x02u  /* Gain /4, +/-160 mV */
#define INA219_CONFIG_PG_GAIN_8_320MV                  0x03u  /* Gain /8, +/-320 mV (default) */

/*   BADC bits [10:7] rw reset 0x03u -- Bus ADC resolution and averaging */
#define INA219_CONFIG_BADC_SHIFT                       7u
#define INA219_CONFIG_BADC_WIDTH                       4u
#define INA219_CONFIG_BADC_MASK                        0x0780u
#define INA219_CONFIG_BADC_GET(reg)                    (((uint16_t)(reg) & 0x0780u) >> 7u)
#define INA219_CONFIG_BADC_SET(reg, val)               (((uint16_t)(reg) & (uint16_t)~0x0780u) | (((uint16_t)(val) << 7u) & 0x0780u))
#define INA219_CONFIG_BADC_RES_9BIT                    0x00u  /* 9-bit, 84 us */
#define INA219_CONFIG_BADC_RES_10BIT                   0x01u  /* 10-bit, 148 us */

Compared with

Related parts

ADS1115
Texas Instruments
4 registers
INA226
Texas Instruments
10 registers
ADXL345
Analog Devices
30 registers

Source

Transcribed from TI INA219 datasheet (SBOS448) (hand-transcribed) (hand-transcribed). Hand-authored seed entry, not machine-extracted. Check against TI INA219 datasheet (SBOS448) before trusting it, then mark it verified.

Raw JSON · Report an error