SparkFun INA2XX Arduino Library  v1.0.0-3-gc9007d6
Arduino Library for the SparkFun Qwiic Power Monitor (INA228 / INA237)
Loading...
Searching...
No Matches
sfDevINA2XX.h File Reference

Header file for the SparkFun INA2XX family base driver. More...

#include <stdint.h>
#include <sfTk/sfToolkit.h>
#include <sfTk/sfTkII2C.h>

Go to the source code of this file.

Classes

union  sfe_ina2xx_config_reg_t
 Bitfield union for the 16-bit CONFIG register (0x00). More...
 
union  sfe_ina2xx_adc_config_reg_t
 Bitfield union for the 16-bit ADC_CONFIG register (0x01). More...
 
union  sfe_ina2xx_diag_alrt_reg_t
 Bitfield union for the 16-bit DIAG_ALRT diagnostic flags and alert register (0x0B). More...
 
class  sfDevINA2XX
 Platform-independent base driver for the INA228/INA237 power monitor ICs. More...
 

Typedefs

typedef enum sfe_ina2xx_mode_t sfe_ina2xx_mode_t
 ADC operating mode settings for the MODE field in ADC_CONFIG (bits [15:12]). More...
 
typedef enum sfe_ina2xx_conv_time_t sfe_ina2xx_conv_time_t
 Conversion time settings shared by the VBUSCT, VSHCT, and VTCT fields. More...
 
typedef enum sfe_ina2xx_avg_count_t sfe_ina2xx_avg_count_t
 ADC averaging count settings for the AVG field in ADC_CONFIG (bits [2:0]). More...
 

Enumerations

enum  sfe_ina2xx_mode_t : uint8_t {
  INA2XX_MODE_SHUTDOWN = 0x0 , INA2XX_MODE_TRIG_BUS = 0x1 , INA2XX_MODE_TRIG_SHUNT = 0x2 , INA2XX_MODE_TRIG_BUS_SHUNT = 0x3 ,
  INA2XX_MODE_TRIG_TEMP = 0x4 , INA2XX_MODE_TRIG_TEMP_BUS = 0x5 , INA2XX_MODE_TRIG_TEMP_SHUNT = 0x6 , INA2XX_MODE_TRIG_ALL = 0x7 ,
  INA2XX_MODE_SHUTDOWN2 = 0x8 , INA2XX_MODE_CONT_BUS = 0x9 , INA2XX_MODE_CONT_SHUNT = 0xA , INA2XX_MODE_CONT_BUS_SHUNT = 0xB ,
  INA2XX_MODE_CONT_TEMP = 0xC , INA2XX_MODE_CONT_TEMP_BUS = 0xD , INA2XX_MODE_CONT_TEMP_SHUNT = 0xE , INA2XX_MODE_CONT_ALL = 0xF
}
 ADC operating mode settings for the MODE field in ADC_CONFIG (bits [15:12]). More...
 
enum  sfe_ina2xx_conv_time_t : uint8_t {
  INA2XX_CONV_50US = 0 , INA2XX_CONV_84US = 1 , INA2XX_CONV_150US = 2 , INA2XX_CONV_280US = 3 ,
  INA2XX_CONV_540US = 4 , INA2XX_CONV_1052US = 5 , INA2XX_CONV_2074US = 6 , INA2XX_CONV_4120US = 7
}
 Conversion time settings shared by the VBUSCT, VSHCT, and VTCT fields. More...
 
enum  sfe_ina2xx_avg_count_t : uint8_t {
  INA2XX_AVG_1 = 0 , INA2XX_AVG_4 = 1 , INA2XX_AVG_16 = 2 , INA2XX_AVG_64 = 3 ,
  INA2XX_AVG_128 = 4 , INA2XX_AVG_256 = 5 , INA2XX_AVG_512 = 6 , INA2XX_AVG_1024 = 7
}
 ADC averaging count settings for the AVG field in ADC_CONFIG (bits [2:0]). More...
 

Detailed Description

Header file for the SparkFun INA2XX family base driver.

sfDevINA2XX is the platform-independent base class for the Texas Instruments INA228 and INA237 digital power/energy monitor ICs. It provides register access for all configuration and diagnostic registers that are shared between both devices:

  • CONFIG (0x00) — system reset, ADC range, conversion delay, temp compensation
  • ADC_CONFIG (0x01) — operating mode, conversion times, averaging
  • SHUNT_CAL (0x02) — shunt calibration value
  • SHUNT_TEMPCO (0x03) — shunt temperature coefficient
  • DIETEMP (0x06) — die temperature measurement
  • DIAG_ALRT (0x0B) — diagnostic flags and alert configuration
  • SOVL/SUVL (0x0C/0x0D) — shunt over/undervoltage thresholds
  • BOVL/BUVL (0x0E/0x0F) — bus over/undervoltage thresholds
  • TEMP_LIMIT (0x10) — temperature over-limit threshold
  • PWR_LIMIT (0x11) — power over-limit threshold
  • MANUFACTURER_ID (0x3E) / DEVICE_ID (0x3F)

Device-specific measurement registers (VSHUNT, VBUS, CURRENT, POWER, ENERGY, CHARGE) are implemented in the derived sfDevINA228 and sfDevINA237 classes because they differ in register width and LSB scaling between the two ICs.

Both devices use 8-bit register addresses and big-endian byte order over I2C.

Most methods return a SparkFun Toolkit error code (::ksfTkErrOk on success, a negative value on error); values read from the device are returned through reference (output) parameters. Callers that do not care about error handling can simply ignore the returned code.

Author
SparkFun Electronics
Date
June 2026

SPDX-License-Identifier: MIT

See also
https://github.com/sparkfun/SparkFun_INA2XX_Arduino_Library

Typedef Documentation

◆ sfe_ina2xx_avg_count_t

ADC averaging count settings for the AVG field in ADC_CONFIG (bits [2:0]).

◆ sfe_ina2xx_conv_time_t

Conversion time settings shared by the VBUSCT, VSHCT, and VTCT fields.

◆ sfe_ina2xx_mode_t

ADC operating mode settings for the MODE field in ADC_CONFIG (bits [15:12]).

Modes 0x0 and 0x8 are both shutdown. Modes 0x1-0x7 are triggered (single-shot). Modes 0x9-0xF are continuous. A typedef is provided so the type can be used without the enum keyword in environments where that matters.

Enumeration Type Documentation

◆ sfe_ina2xx_avg_count_t

enum sfe_ina2xx_avg_count_t : uint8_t

ADC averaging count settings for the AVG field in ADC_CONFIG (bits [2:0]).

Enumerator
INA2XX_AVG_1 

1 sample (no averaging, default)

INA2XX_AVG_4 

4 samples

INA2XX_AVG_16 

16 samples

INA2XX_AVG_64 

64 samples

INA2XX_AVG_128 

128 samples

INA2XX_AVG_256 

256 samples

INA2XX_AVG_512 

512 samples

INA2XX_AVG_1024 

1024 samples

◆ sfe_ina2xx_conv_time_t

enum sfe_ina2xx_conv_time_t : uint8_t

Conversion time settings shared by the VBUSCT, VSHCT, and VTCT fields.

Enumerator
INA2XX_CONV_50US 

50 us

INA2XX_CONV_84US 

84 us

INA2XX_CONV_150US 

150 us

INA2XX_CONV_280US 

280 us

INA2XX_CONV_540US 

540 us

INA2XX_CONV_1052US 

1052 us (default)

INA2XX_CONV_2074US 

2074 us

INA2XX_CONV_4120US 

4120 us

◆ sfe_ina2xx_mode_t

enum sfe_ina2xx_mode_t : uint8_t

ADC operating mode settings for the MODE field in ADC_CONFIG (bits [15:12]).

Modes 0x0 and 0x8 are both shutdown. Modes 0x1-0x7 are triggered (single-shot). Modes 0x9-0xF are continuous. A typedef is provided so the type can be used without the enum keyword in environments where that matters.

Enumerator
INA2XX_MODE_SHUTDOWN 

Shutdown.

INA2XX_MODE_TRIG_BUS 

Triggered bus voltage, single shot.

INA2XX_MODE_TRIG_SHUNT 

Triggered shunt voltage, single shot.

INA2XX_MODE_TRIG_BUS_SHUNT 

Triggered bus + shunt, single shot.

INA2XX_MODE_TRIG_TEMP 

Triggered temperature, single shot.

INA2XX_MODE_TRIG_TEMP_BUS 

Triggered temp + bus, single shot.

INA2XX_MODE_TRIG_TEMP_SHUNT 

Triggered temp + shunt, single shot.

INA2XX_MODE_TRIG_ALL 

Triggered bus + shunt + temp, single shot.

INA2XX_MODE_SHUTDOWN2 

Shutdown (alternate)

INA2XX_MODE_CONT_BUS 

Continuous bus voltage only.

INA2XX_MODE_CONT_SHUNT 

Continuous shunt voltage only.

INA2XX_MODE_CONT_BUS_SHUNT 

Continuous bus + shunt.

INA2XX_MODE_CONT_TEMP 

Continuous temperature only.

INA2XX_MODE_CONT_TEMP_BUS 

Continuous temp + bus.

INA2XX_MODE_CONT_TEMP_SHUNT 

Continuous temp + shunt.

INA2XX_MODE_CONT_ALL 

Continuous bus + shunt + temp (default)