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

Platform-independent base driver for the INA228/INA237 power monitor ICs. More...

#include <sfDevINA2XX.h>

Inheritance diagram for sfDevINA2XX:
sfDevINA228 sfDevINA237 SfeINA228ArdI2C SfeINA237ArdI2C

Public Member Functions

 sfDevINA2XX ()
 
sfTkError_t begin (sfTkIBus *theBus=nullptr)
 Initialize the device driver with the given bus. More...
 
void setCommunicationBus (sfTkIBus *theBus)
 Set the communication bus pointer. More...
 
sfTkError_t getManufacturerID (uint16_t &id)
 Read the Manufacturer ID register (0x3E). More...
 
sfTkError_t getDeviceID (uint16_t &id)
 Read the Device ID register (0x3F). More...
 
sfTkError_t reset (void)
 Perform a full system reset via the RST bit in CONFIG. More...
 
sfTkError_t resetAccumulators (void)
 Reset the energy and charge accumulators (INA228 RSTACC bit). More...
 
sfTkError_t setADCRange (bool reducedRange)
 Set the ADC full-scale shunt range. More...
 
sfTkError_t getADCRange (bool &reducedRange)
 Get the current ADC range setting. More...
 
sfTkError_t setConversionDelay (uint8_t delay2ms)
 Set the initial conversion delay in 2ms steps. More...
 
sfTkError_t getConversionDelay (uint8_t &delay2ms)
 Get the current conversion delay setting. More...
 
sfTkError_t enableTempCompensation (bool enable)
 Enable or disable shunt temperature compensation. More...
 
sfTkError_t getTempCompensation (bool &enabled)
 Get the temperature compensation enable state. More...
 
sfTkError_t setADCMode (sfe_ina2xx_mode_t mode)
 Set the ADC operating mode. More...
 
sfTkError_t getADCMode (sfe_ina2xx_mode_t &mode)
 Get the current ADC operating mode. More...
 
sfTkError_t setBusVoltageConvTime (sfe_ina2xx_conv_time_t time)
 Set the bus voltage conversion time. More...
 
sfTkError_t getBusVoltageConvTime (sfe_ina2xx_conv_time_t &time)
 Get the bus voltage conversion time. More...
 
sfTkError_t setShuntVoltageConvTime (sfe_ina2xx_conv_time_t time)
 Set the shunt voltage conversion time. More...
 
sfTkError_t getShuntVoltageConvTime (sfe_ina2xx_conv_time_t &time)
 Get the shunt voltage conversion time. More...
 
sfTkError_t setTempConvTime (sfe_ina2xx_conv_time_t time)
 Set the temperature conversion time. More...
 
sfTkError_t getTempConvTime (sfe_ina2xx_conv_time_t &time)
 Get the temperature conversion time. More...
 
sfTkError_t setAveragingCount (sfe_ina2xx_avg_count_t count)
 Set the ADC averaging count. More...
 
sfTkError_t getAveragingCount (sfe_ina2xx_avg_count_t &count)
 Get the current ADC averaging count. More...
 
sfTkError_t setShuntCal (uint16_t calValue)
 Write a raw value to the SHUNT_CAL register. More...
 
sfTkError_t getShuntCal (uint16_t &calValue)
 Read the current SHUNT_CAL register value. More...
 
sfTkError_t setShuntTempCoefficient (uint16_t ppmPerDegC)
 Set the shunt temperature coefficient for temperature compensation. More...
 
sfTkError_t getShuntTempCoefficient (uint16_t &ppmPerDegC)
 Get the shunt temperature coefficient. More...
 
sfTkError_t getDiagnosticFlags (sfe_ina2xx_diag_alrt_reg_t &flags)
 Read the full DIAG_ALRT register. More...
 
sfTkError_t setAlertLatch (bool latched)
 Enable or disable alert latching. More...
 
sfTkError_t getAlertLatch (bool &latched)
 Get the alert latch setting. More...
 
sfTkError_t setConversionReadyAlert (bool enable)
 Enable conversion ready flag on the ALERT pin. More...
 
sfTkError_t getConversionReadyAlert (bool &enabled)
 Get the conversion ready alert enable state. More...
 
sfTkError_t setSlowAlert (bool enable)
 Enable alert comparison on averaged (vs. More...
 
sfTkError_t getSlowAlert (bool &enabled)
 Get the slow alert enable state. More...
 
sfTkError_t setAlertPolarity (bool activeHigh)
 Set the ALERT pin polarity. More...
 
sfTkError_t getAlertPolarity (bool &activeHigh)
 Get the ALERT pin polarity setting. More...
 
sfTkError_t isEnergyOverflow (bool &overflow)
 Check if the energy register has overflowed (INA228 only). More...
 
sfTkError_t isChargeOverflow (bool &overflow)
 Check if the charge register has overflowed (INA228 only). More...
 
sfTkError_t isMathOverflow (bool &overflow)
 Check if a math overflow has occurred in current/power calculations. More...
 
sfTkError_t isTempOverLimit (bool &overLimit)
 Check if the temperature over-limit flag is set. More...
 
sfTkError_t isShuntOverVoltage (bool &overVoltage)
 Check if the shunt overvoltage flag is set. More...
 
sfTkError_t isShuntUnderVoltage (bool &underVoltage)
 Check if the shunt undervoltage flag is set. More...
 
sfTkError_t isBusOverVoltage (bool &overVoltage)
 Check if the bus overvoltage flag is set. More...
 
sfTkError_t isBusUnderVoltage (bool &underVoltage)
 Check if the bus undervoltage flag is set. More...
 
sfTkError_t isPowerOverLimit (bool &overLimit)
 Check if the power over-limit flag is set. More...
 
sfTkError_t isConversionReady (bool &ready)
 Check if a conversion has completed. More...
 
sfTkError_t isMemoryValid (bool &valid)
 Check the memory checksum status. More...
 
sfTkError_t setShuntOverVoltageThreshold (int16_t threshold)
 Set the shunt overvoltage threshold. More...
 
sfTkError_t getShuntOverVoltageThreshold (int16_t &threshold)
 Get the shunt overvoltage threshold. More...
 
sfTkError_t setShuntUnderVoltageThreshold (int16_t threshold)
 Set the shunt undervoltage threshold. More...
 
sfTkError_t getShuntUnderVoltageThreshold (int16_t &threshold)
 Get the shunt undervoltage threshold. More...
 
sfTkError_t setBusOverVoltageThreshold (uint16_t threshold)
 Set the bus overvoltage threshold. More...
 
sfTkError_t getBusOverVoltageThreshold (uint16_t &threshold)
 Get the bus overvoltage threshold. More...
 
sfTkError_t setBusUnderVoltageThreshold (uint16_t threshold)
 Set the bus undervoltage threshold. More...
 
sfTkError_t getBusUnderVoltageThreshold (uint16_t &threshold)
 Get the bus undervoltage threshold. More...
 
sfTkError_t setTempLimitThreshold (int16_t threshold)
 Set the temperature over-limit threshold. More...
 
sfTkError_t getTempLimitThreshold (int16_t &threshold)
 Get the temperature over-limit threshold. More...
 
sfTkError_t setPowerLimitThreshold (uint16_t threshold)
 Set the power over-limit threshold. More...
 
sfTkError_t getPowerLimitThreshold (uint16_t &threshold)
 Get the power over-limit threshold. More...
 

Protected Member Functions

sfTkError_t readRegister24 (uint8_t reg, uint32_t &value)
 Read 3 bytes (24-bit) from a register into a uint32_t. More...
 
sfTkError_t readRegister40 (uint8_t reg, uint64_t &value)
 Read 5 bytes (40-bit) from a register into a uint64_t. More...
 
sfTkError_t calibrateImpl (float shuntResOhms, float maxCurrentA, float calScale, float currentFullScale)
 Shared calibration math; only the two scale constants differ per device. More...
 
sfTkError_t powerToWatts (float &watts, float powerLSBScale)
 Shared POWER -> watts conversion. powerLSBScale is 3.2 (INA228) or 0.2 (INA237). More...
 
sfTkError_t dieTemperatureToCelsius (float &celsius, uint8_t shift, float tempLSB)
 Shared DIETEMP -> Celsius conversion. More...
 
sfTkError_t readPowerRaw (uint32_t &value)
 Shared raw POWER read (24-bit, unsigned) — identical on both devices. More...
 
template<typename T , bool Wide>
sfTkError_t readSignedMeasurementRaw (uint8_t reg, T &value)
 Shared raw read for a signed measurement register (shunt voltage, current). More...
 
template<typename T , bool Wide>
sfTkError_t readUnsignedMeasurementRaw (uint8_t reg, T &value)
 Shared raw read for an unsigned measurement register (bus voltage). More...
 
template<typename T , bool Wide>
sfTkError_t shuntVoltageToMilliVolts (float &milliVolts, float lsbDefault, float lsbReduced)
 Shared VSHUNT -> millivolts conversion (reads raw, then scales by the range LSB). More...
 
template<typename T , bool Wide>
sfTkError_t busVoltageToVolts (float &volts, float busLSB)
 Shared VBUS -> volts conversion. More...
 
template<typename T , bool Wide>
sfTkError_t currentToAmps (float &amps)
 Shared CURRENT -> amps conversion (scales by the calibrated CURRENT_LSB). More...
 

Protected Attributes

sfTkIBus * _theBus
 Pointer to the communication bus device. More...
 
float _currentLSB
 Current measurement LSB in Amps, set during calibration. More...
 
bool _adcRange
 Cached ADC range: false = +/-163.84mV, true = +/-40.96mV. More...
 
float _shuntRes
 Shunt resistance in Ohms, stored during calibration. More...
 

Static Protected Attributes

static const uint8_t kI2CAddress = 0x40
 Default 7-bit I2C address for the SparkFun Qwiic Power Monitor board. More...
 
static const uint8_t kRegConfig = 0x00
 Configuration register (16-bit, R/W) More...
 
static const uint8_t kRegAdcConfig = 0x01
 ADC Configuration register (16-bit, R/W) More...
 
static const uint8_t kRegShuntCal = 0x02
 Shunt Calibration register (16-bit, R/W) More...
 
static const uint8_t kRegShuntTempCo = 0x03
 Shunt Temperature Coefficient (16-bit, R/W) More...
 
static const uint8_t kRegVShunt = 0x04
 Shunt Voltage Measurement (24/16-bit, R) More...
 
static const uint8_t kRegVBus = 0x05
 Bus Voltage Measurement (24/16-bit, R) More...
 
static const uint8_t kRegDieTemp = 0x06
 Die Temperature Measurement (16-bit, R) More...
 
static const uint8_t kRegCurrent = 0x07
 Current Result (24/16-bit, R) More...
 
static const uint8_t kRegPower = 0x08
 Power Result (24-bit, R) More...
 
static const uint8_t kRegEnergy = 0x09
 Energy Result (40-bit, R) – INA228 only. More...
 
static const uint8_t kRegCharge = 0x0A
 Charge Result (40-bit, R) – INA228 only. More...
 
static const uint8_t kRegDiagAlrt = 0x0B
 Diagnostic Flags and Alert (16-bit, R/W) More...
 
static const uint8_t kRegSOVL = 0x0C
 Shunt Overvoltage Threshold (16-bit, R/W) More...
 
static const uint8_t kRegSUVL = 0x0D
 Shunt Undervoltage Threshold (16-bit, R/W) More...
 
static const uint8_t kRegBOVL = 0x0E
 Bus Overvoltage Threshold (16-bit, R/W) More...
 
static const uint8_t kRegBUVL = 0x0F
 Bus Undervoltage Threshold (16-bit, R/W) More...
 
static const uint8_t kRegTempLimit = 0x10
 Temperature Over-Limit Threshold (16-bit, R/W) More...
 
static const uint8_t kRegPowerLimit = 0x11
 Power Over-Limit Threshold (16-bit, R/W) More...
 
static const uint8_t kRegManufacturerID = 0x3E
 Manufacturer ID (16-bit, R) – reads 0x5449 ("TI") More...
 
static const uint8_t kRegDeviceID = 0x3F
 Device ID (16-bit, R) More...
 
static const uint16_t kShuntCalMask = 0x7FFF
 SHUNT_CAL valid bits [14:0] (bit 15 reserved) More...
 
static const uint16_t kBusThresholdMask = 0x7FFF
 BOVL/BUVL valid bits [14:0] (bit 15 reserved) More...
 
static const uint16_t kShuntTempCoMask = 0x3FFF
 TEMPCO field mask, bits [13:0]. More...
 
static const uint16_t kINA228DeviceIDValue = 0x2280
 INA228 device ID (upper 12 bits) More...
 
static const uint16_t kINA237DeviceIDValue = 0x2370
 INA237 device ID (upper 12 bits) More...
 
static const uint16_t kINA238DeviceIDValue = 0x2380
 INA238 device ID (register-compatible with INA237) More...
 
static const uint16_t kDeviceIDMask = 0xFFF0
 Mask for device ID (ignore revision) More...
 
static const uint16_t kManufacturerIDValue = 0x5449
 "TI" in ASCII More...
 

Detailed Description

Platform-independent base driver for the INA228/INA237 power monitor ICs.

This class implements register-level access for all configuration and diagnostic registers shared between the INA228 and INA237. Measurement registers (VSHUNT, VBUS, CURRENT, POWER, ENERGY, CHARGE) are implemented in the derived sfDevINA228 and sfDevINA237 classes because they differ in register width and scaling.

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.

This class does not depend on Arduino. The Arduino-specific wrappers (SfeINA228ArdI2C, SfeINA237ArdI2C) provide begin() and isConnected() methods.

Constructor & Destructor Documentation

◆ sfDevINA2XX()

sfDevINA2XX::sfDevINA2XX ( )
inline

Member Function Documentation

◆ begin()

sfTkError_t sfDevINA2XX::begin ( sfTkIBus *  theBus = nullptr)

Initialize the device driver with the given bus.

Sets the communication bus and configures byte order for big-endian.

Parameters
theBusPointer to the initialized bus object. If null, a bus set by a prior call is used.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ busVoltageToVolts()

template<typename T , bool Wide>
sfTkError_t sfDevINA2XX::busVoltageToVolts ( float &  volts,
float  busLSB 
)
inlineprotected

Shared VBUS -> volts conversion.

◆ calibrateImpl()

sfTkError_t sfDevINA2XX::calibrateImpl ( float  shuntResOhms,
float  maxCurrentA,
float  calScale,
float  currentFullScale 
)
protected

Shared calibration math; only the two scale constants differ per device.

Parameters
calScaleDevice calibration scale (13107.2e6 for INA228, 819.2e6 for INA237).
currentFullScalePositive half of the ADC range (2^19 for INA228, 2^15 for INA237).

◆ currentToAmps()

template<typename T , bool Wide>
sfTkError_t sfDevINA2XX::currentToAmps ( float &  amps)
inlineprotected

Shared CURRENT -> amps conversion (scales by the calibrated CURRENT_LSB).

◆ dieTemperatureToCelsius()

sfTkError_t sfDevINA2XX::dieTemperatureToCelsius ( float &  celsius,
uint8_t  shift,
float  tempLSB 
)
protected

Shared DIETEMP -> Celsius conversion.

Parameters
shiftRight-shift before sign interpretation: 0 (INA228, 16-bit) or 4 (INA237, 12-bit).

◆ enableTempCompensation()

sfTkError_t sfDevINA2XX::enableTempCompensation ( bool  enable)

Enable or disable shunt temperature compensation.

Parameters
enableTrue to enable, false to disable.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getADCMode()

sfTkError_t sfDevINA2XX::getADCMode ( sfe_ina2xx_mode_t mode)

Get the current ADC operating mode.

Parameters
modeOutput reference that receives the operating mode.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getADCRange()

sfTkError_t sfDevINA2XX::getADCRange ( bool &  reducedRange)

Get the current ADC range setting.

Parameters
reducedRangeOutput reference set true if reduced range (+/-40.96mV), false if default.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getAlertLatch()

sfTkError_t sfDevINA2XX::getAlertLatch ( bool &  latched)

Get the alert latch setting.

Parameters
latchedOutput reference set true if latched, false if transparent.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getAlertPolarity()

sfTkError_t sfDevINA2XX::getAlertPolarity ( bool &  activeHigh)

Get the ALERT pin polarity setting.

Parameters
activeHighOutput reference set true if active-high, false if active-low.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getAveragingCount()

sfTkError_t sfDevINA2XX::getAveragingCount ( sfe_ina2xx_avg_count_t count)

Get the current ADC averaging count.

Parameters
countOutput reference that receives the averaging count setting.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getBusOverVoltageThreshold()

sfTkError_t sfDevINA2XX::getBusOverVoltageThreshold ( uint16_t &  threshold)

Get the bus overvoltage threshold.

Parameters
thresholdOutput reference that receives the threshold value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getBusUnderVoltageThreshold()

sfTkError_t sfDevINA2XX::getBusUnderVoltageThreshold ( uint16_t &  threshold)

Get the bus undervoltage threshold.

Parameters
thresholdOutput reference that receives the threshold value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getBusVoltageConvTime()

sfTkError_t sfDevINA2XX::getBusVoltageConvTime ( sfe_ina2xx_conv_time_t time)

Get the bus voltage conversion time.

Parameters
timeOutput reference that receives the conversion time setting.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getConversionDelay()

sfTkError_t sfDevINA2XX::getConversionDelay ( uint8_t &  delay2ms)

Get the current conversion delay setting.

Parameters
delay2msOutput reference that receives the delay value 0-255.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getConversionReadyAlert()

sfTkError_t sfDevINA2XX::getConversionReadyAlert ( bool &  enabled)

Get the conversion ready alert enable state.

Parameters
enabledOutput reference set true if enabled.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getDeviceID()

sfTkError_t sfDevINA2XX::getDeviceID ( uint16_t &  id)

Read the Device ID register (0x3F).

Parameters
idOutput reference that receives the full 16-bit device ID (including revision nibble).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getDiagnosticFlags()

sfTkError_t sfDevINA2XX::getDiagnosticFlags ( sfe_ina2xx_diag_alrt_reg_t flags)

Read the full DIAG_ALRT register.

Reading this register clears latched alert flags when ALATCH = 1.

Parameters
flagsOutput reference that receives the diagnostic flags bitfield.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getManufacturerID()

sfTkError_t sfDevINA2XX::getManufacturerID ( uint16_t &  id)

Read the Manufacturer ID register (0x3E).

Parameters
idOutput reference that receives the manufacturer ID (0x5449 = "TI").
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getPowerLimitThreshold()

sfTkError_t sfDevINA2XX::getPowerLimitThreshold ( uint16_t &  threshold)

Get the power over-limit threshold.

Parameters
thresholdOutput reference that receives the threshold value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getShuntCal()

sfTkError_t sfDevINA2XX::getShuntCal ( uint16_t &  calValue)

Read the current SHUNT_CAL register value.

Parameters
calValueOutput reference that receives the calibration value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getShuntOverVoltageThreshold()

sfTkError_t sfDevINA2XX::getShuntOverVoltageThreshold ( int16_t &  threshold)

Get the shunt overvoltage threshold.

Parameters
thresholdOutput reference that receives the threshold value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getShuntTempCoefficient()

sfTkError_t sfDevINA2XX::getShuntTempCoefficient ( uint16_t &  ppmPerDegC)

Get the shunt temperature coefficient.

Parameters
ppmPerDegCOutput reference that receives the temperature coefficient in ppm/deg-C.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getShuntUnderVoltageThreshold()

sfTkError_t sfDevINA2XX::getShuntUnderVoltageThreshold ( int16_t &  threshold)

Get the shunt undervoltage threshold.

Parameters
thresholdOutput reference that receives the threshold value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getShuntVoltageConvTime()

sfTkError_t sfDevINA2XX::getShuntVoltageConvTime ( sfe_ina2xx_conv_time_t time)

Get the shunt voltage conversion time.

Parameters
timeOutput reference that receives the conversion time setting.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getSlowAlert()

sfTkError_t sfDevINA2XX::getSlowAlert ( bool &  enabled)

Get the slow alert enable state.

Parameters
enabledOutput reference set true if alert compares on averaged value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getTempCompensation()

sfTkError_t sfDevINA2XX::getTempCompensation ( bool &  enabled)

Get the temperature compensation enable state.

Parameters
enabledOutput reference set true if enabled.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getTempConvTime()

sfTkError_t sfDevINA2XX::getTempConvTime ( sfe_ina2xx_conv_time_t time)

Get the temperature conversion time.

Parameters
timeOutput reference that receives the conversion time setting.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ getTempLimitThreshold()

sfTkError_t sfDevINA2XX::getTempLimitThreshold ( int16_t &  threshold)

Get the temperature over-limit threshold.

Parameters
thresholdOutput reference that receives the threshold value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isBusOverVoltage()

sfTkError_t sfDevINA2XX::isBusOverVoltage ( bool &  overVoltage)

Check if the bus overvoltage flag is set.

Parameters
overVoltageOutput reference set true if bus voltage exceeds BOVL threshold.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isBusUnderVoltage()

sfTkError_t sfDevINA2XX::isBusUnderVoltage ( bool &  underVoltage)

Check if the bus undervoltage flag is set.

Parameters
underVoltageOutput reference set true if bus voltage is below BUVL threshold.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isChargeOverflow()

sfTkError_t sfDevINA2XX::isChargeOverflow ( bool &  overflow)

Check if the charge register has overflowed (INA228 only).

Parameters
overflowOutput reference set true if overflow detected.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isConversionReady()

sfTkError_t sfDevINA2XX::isConversionReady ( bool &  ready)

Check if a conversion has completed.

Parameters
readyOutput reference set true if conversion ready.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isEnergyOverflow()

sfTkError_t sfDevINA2XX::isEnergyOverflow ( bool &  overflow)

Check if the energy register has overflowed (INA228 only).

Parameters
overflowOutput reference set true if overflow detected.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isMathOverflow()

sfTkError_t sfDevINA2XX::isMathOverflow ( bool &  overflow)

Check if a math overflow has occurred in current/power calculations.

Parameters
overflowOutput reference set true if overflow detected.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isMemoryValid()

sfTkError_t sfDevINA2XX::isMemoryValid ( bool &  valid)

Check the memory checksum status.

Parameters
validOutput reference set true if the internal memory checksum is valid.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isPowerOverLimit()

sfTkError_t sfDevINA2XX::isPowerOverLimit ( bool &  overLimit)

Check if the power over-limit flag is set.

Parameters
overLimitOutput reference set true if power exceeds PWR_LIMIT threshold.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isShuntOverVoltage()

sfTkError_t sfDevINA2XX::isShuntOverVoltage ( bool &  overVoltage)

Check if the shunt overvoltage flag is set.

Parameters
overVoltageOutput reference set true if shunt voltage exceeds SOVL threshold.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isShuntUnderVoltage()

sfTkError_t sfDevINA2XX::isShuntUnderVoltage ( bool &  underVoltage)

Check if the shunt undervoltage flag is set.

Parameters
underVoltageOutput reference set true if shunt voltage is below SUVL threshold.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ isTempOverLimit()

sfTkError_t sfDevINA2XX::isTempOverLimit ( bool &  overLimit)

Check if the temperature over-limit flag is set.

Parameters
overLimitOutput reference set true if temperature exceeds TEMP_LIMIT threshold.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ powerToWatts()

sfTkError_t sfDevINA2XX::powerToWatts ( float &  watts,
float  powerLSBScale 
)
protected

Shared POWER -> watts conversion. powerLSBScale is 3.2 (INA228) or 0.2 (INA237).

◆ readPowerRaw()

sfTkError_t sfDevINA2XX::readPowerRaw ( uint32_t &  value)
protected

Shared raw POWER read (24-bit, unsigned) — identical on both devices.

◆ readRegister24()

sfTkError_t sfDevINA2XX::readRegister24 ( uint8_t  reg,
uint32_t &  value 
)
protected

Read 3 bytes (24-bit) from a register into a uint32_t.

Parameters
regRegister address.
valueOutput value (MSB-first assembly).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ readRegister40()

sfTkError_t sfDevINA2XX::readRegister40 ( uint8_t  reg,
uint64_t &  value 
)
protected

Read 5 bytes (40-bit) from a register into a uint64_t.

Parameters
regRegister address.
valueOutput value (MSB-first assembly).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ readSignedMeasurementRaw()

template<typename T , bool Wide>
sfTkError_t sfDevINA2XX::readSignedMeasurementRaw ( uint8_t  reg,
T &  value 
)
inlineprotected

Shared raw read for a signed measurement register (shunt voltage, current).

Template Parameters
TOutput integer type (int32_t for the 24-bit INA228, int16_t for INA237).
Widetrue = 24-bit register, data in bits [23:4], 20-bit sign extension (INA228); false = 16-bit two's complement read directly (INA237).

◆ readUnsignedMeasurementRaw()

template<typename T , bool Wide>
sfTkError_t sfDevINA2XX::readUnsignedMeasurementRaw ( uint8_t  reg,
T &  value 
)
inlineprotected

Shared raw read for an unsigned measurement register (bus voltage).

Template Parameters
TOutput integer type (uint32_t for INA228, uint16_t for INA237).
Widetrue = 24-bit register, data in bits [23:4] (INA228); false = 16-bit read (INA237).

◆ reset()

sfTkError_t sfDevINA2XX::reset ( void  )

Perform a full system reset via the RST bit in CONFIG.

Returns
::ksfTkErrOk on success, or an error code on failure.

◆ resetAccumulators()

sfTkError_t sfDevINA2XX::resetAccumulators ( void  )

Reset the energy and charge accumulators (INA228 RSTACC bit).

Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setADCMode()

sfTkError_t sfDevINA2XX::setADCMode ( sfe_ina2xx_mode_t  mode)

Set the ADC operating mode.

Parameters
modeOperating mode (see sfe_ina2xx_mode_t).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setADCRange()

sfTkError_t sfDevINA2XX::setADCRange ( bool  reducedRange)

Set the ADC full-scale shunt range.

Parameters
reducedRangeFalse = +/-163.84mV (default), true = +/-40.96mV.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setAlertLatch()

sfTkError_t sfDevINA2XX::setAlertLatch ( bool  latched)

Enable or disable alert latching.

Parameters
latchedTrue = latched mode, false = transparent mode.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setAlertPolarity()

sfTkError_t sfDevINA2XX::setAlertPolarity ( bool  activeHigh)

Set the ALERT pin polarity.

Parameters
activeHighTrue = active-high, false = active-low (default, open-drain).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setAveragingCount()

sfTkError_t sfDevINA2XX::setAveragingCount ( sfe_ina2xx_avg_count_t  count)

Set the ADC averaging count.

Parameters
countAveraging count (see sfe_ina2xx_avg_count_t).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setBusOverVoltageThreshold()

sfTkError_t sfDevINA2XX::setBusOverVoltageThreshold ( uint16_t  threshold)

Set the bus overvoltage threshold.

Parameters
thresholdUnsigned 15-bit value. LSB = 3.125mV.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setBusUnderVoltageThreshold()

sfTkError_t sfDevINA2XX::setBusUnderVoltageThreshold ( uint16_t  threshold)

Set the bus undervoltage threshold.

Parameters
thresholdUnsigned 15-bit value. LSB = 3.125mV.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setBusVoltageConvTime()

sfTkError_t sfDevINA2XX::setBusVoltageConvTime ( sfe_ina2xx_conv_time_t  time)

Set the bus voltage conversion time.

Parameters
timeConversion time setting (see sfe_ina2xx_conv_time_t).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setCommunicationBus()

void sfDevINA2XX::setCommunicationBus ( sfTkIBus *  theBus)

Set the communication bus pointer.

Parameters
theBusBus to use for all register I/O.

◆ setConversionDelay()

sfTkError_t sfDevINA2XX::setConversionDelay ( uint8_t  delay2ms)

Set the initial conversion delay in 2ms steps.

Parameters
delay2msDelay value 0-255 (0 = 0ms, 255 = 510ms).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setConversionReadyAlert()

sfTkError_t sfDevINA2XX::setConversionReadyAlert ( bool  enable)

Enable conversion ready flag on the ALERT pin.

Parameters
enableTrue to assert ALERT on conversion complete.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setPowerLimitThreshold()

sfTkError_t sfDevINA2XX::setPowerLimitThreshold ( uint16_t  threshold)

Set the power over-limit threshold.

Parameters
thresholdUnsigned value. LSB = 256 x Power LSB.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setShuntCal()

sfTkError_t sfDevINA2XX::setShuntCal ( uint16_t  calValue)

Write a raw value to the SHUNT_CAL register.

Parameters
calValue15-bit calibration value (bit 15 is reserved).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setShuntOverVoltageThreshold()

sfTkError_t sfDevINA2XX::setShuntOverVoltageThreshold ( int16_t  threshold)

Set the shunt overvoltage threshold.

Parameters
thresholdTwo's complement value. LSB = 5uV (ADCRANGE=0) or 1.25uV (ADCRANGE=1).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setShuntTempCoefficient()

sfTkError_t sfDevINA2XX::setShuntTempCoefficient ( uint16_t  ppmPerDegC)

Set the shunt temperature coefficient for temperature compensation.

Parameters
ppmPerDegCTemperature coefficient, 0-16383 ppm/deg-C.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setShuntUnderVoltageThreshold()

sfTkError_t sfDevINA2XX::setShuntUnderVoltageThreshold ( int16_t  threshold)

Set the shunt undervoltage threshold.

Parameters
thresholdTwo's complement value. Same LSB as shunt overvoltage.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setShuntVoltageConvTime()

sfTkError_t sfDevINA2XX::setShuntVoltageConvTime ( sfe_ina2xx_conv_time_t  time)

Set the shunt voltage conversion time.

Parameters
timeConversion time setting (see sfe_ina2xx_conv_time_t).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setSlowAlert()

sfTkError_t sfDevINA2XX::setSlowAlert ( bool  enable)

Enable alert comparison on averaged (vs.

instantaneous) values.

Parameters
enableTrue = alert on averaged value, false = alert on ADC value.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setTempConvTime()

sfTkError_t sfDevINA2XX::setTempConvTime ( sfe_ina2xx_conv_time_t  time)

Set the temperature conversion time.

Parameters
timeConversion time setting (see sfe_ina2xx_conv_time_t).
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ setTempLimitThreshold()

sfTkError_t sfDevINA2XX::setTempLimitThreshold ( int16_t  threshold)

Set the temperature over-limit threshold.

Parameters
thresholdTwo's complement value. LSB = 7.8125 m-deg-C.
Returns
::ksfTkErrOk on success, or an error code on failure.

◆ shuntVoltageToMilliVolts()

template<typename T , bool Wide>
sfTkError_t sfDevINA2XX::shuntVoltageToMilliVolts ( float &  milliVolts,
float  lsbDefault,
float  lsbReduced 
)
inlineprotected

Shared VSHUNT -> millivolts conversion (reads raw, then scales by the range LSB).

Member Data Documentation

◆ _adcRange

bool sfDevINA2XX::_adcRange
protected

Cached ADC range: false = +/-163.84mV, true = +/-40.96mV.

◆ _currentLSB

float sfDevINA2XX::_currentLSB
protected

Current measurement LSB in Amps, set during calibration.

◆ _shuntRes

float sfDevINA2XX::_shuntRes
protected

Shunt resistance in Ohms, stored during calibration.

◆ _theBus

sfTkIBus* sfDevINA2XX::_theBus
protected

Pointer to the communication bus device.

◆ kBusThresholdMask

const uint16_t sfDevINA2XX::kBusThresholdMask = 0x7FFF
staticprotected

BOVL/BUVL valid bits [14:0] (bit 15 reserved)

◆ kDeviceIDMask

const uint16_t sfDevINA2XX::kDeviceIDMask = 0xFFF0
staticprotected

Mask for device ID (ignore revision)

◆ kI2CAddress

const uint8_t sfDevINA2XX::kI2CAddress = 0x40
staticprotected

Default 7-bit I2C address for the SparkFun Qwiic Power Monitor board.

A0 = GND, A1 = GND gives 0x40. Both INA228 and INA237 support 0x40-0x4F.

◆ kINA228DeviceIDValue

const uint16_t sfDevINA2XX::kINA228DeviceIDValue = 0x2280
staticprotected

INA228 device ID (upper 12 bits)

◆ kINA237DeviceIDValue

const uint16_t sfDevINA2XX::kINA237DeviceIDValue = 0x2370
staticprotected

INA237 device ID (upper 12 bits)

◆ kINA238DeviceIDValue

const uint16_t sfDevINA2XX::kINA238DeviceIDValue = 0x2380
staticprotected

INA238 device ID (register-compatible with INA237)

◆ kManufacturerIDValue

const uint16_t sfDevINA2XX::kManufacturerIDValue = 0x5449
staticprotected

"TI" in ASCII

◆ kRegAdcConfig

const uint8_t sfDevINA2XX::kRegAdcConfig = 0x01
staticprotected

ADC Configuration register (16-bit, R/W)

◆ kRegBOVL

const uint8_t sfDevINA2XX::kRegBOVL = 0x0E
staticprotected

Bus Overvoltage Threshold (16-bit, R/W)

◆ kRegBUVL

const uint8_t sfDevINA2XX::kRegBUVL = 0x0F
staticprotected

Bus Undervoltage Threshold (16-bit, R/W)

◆ kRegCharge

const uint8_t sfDevINA2XX::kRegCharge = 0x0A
staticprotected

Charge Result (40-bit, R) – INA228 only.

◆ kRegConfig

const uint8_t sfDevINA2XX::kRegConfig = 0x00
staticprotected

Configuration register (16-bit, R/W)

◆ kRegCurrent

const uint8_t sfDevINA2XX::kRegCurrent = 0x07
staticprotected

Current Result (24/16-bit, R)

◆ kRegDeviceID

const uint8_t sfDevINA2XX::kRegDeviceID = 0x3F
staticprotected

Device ID (16-bit, R)

◆ kRegDiagAlrt

const uint8_t sfDevINA2XX::kRegDiagAlrt = 0x0B
staticprotected

Diagnostic Flags and Alert (16-bit, R/W)

◆ kRegDieTemp

const uint8_t sfDevINA2XX::kRegDieTemp = 0x06
staticprotected

Die Temperature Measurement (16-bit, R)

◆ kRegEnergy

const uint8_t sfDevINA2XX::kRegEnergy = 0x09
staticprotected

Energy Result (40-bit, R) – INA228 only.

◆ kRegManufacturerID

const uint8_t sfDevINA2XX::kRegManufacturerID = 0x3E
staticprotected

Manufacturer ID (16-bit, R) – reads 0x5449 ("TI")

◆ kRegPower

const uint8_t sfDevINA2XX::kRegPower = 0x08
staticprotected

Power Result (24-bit, R)

◆ kRegPowerLimit

const uint8_t sfDevINA2XX::kRegPowerLimit = 0x11
staticprotected

Power Over-Limit Threshold (16-bit, R/W)

◆ kRegShuntCal

const uint8_t sfDevINA2XX::kRegShuntCal = 0x02
staticprotected

Shunt Calibration register (16-bit, R/W)

◆ kRegShuntTempCo

const uint8_t sfDevINA2XX::kRegShuntTempCo = 0x03
staticprotected

Shunt Temperature Coefficient (16-bit, R/W)

◆ kRegSOVL

const uint8_t sfDevINA2XX::kRegSOVL = 0x0C
staticprotected

Shunt Overvoltage Threshold (16-bit, R/W)

◆ kRegSUVL

const uint8_t sfDevINA2XX::kRegSUVL = 0x0D
staticprotected

Shunt Undervoltage Threshold (16-bit, R/W)

◆ kRegTempLimit

const uint8_t sfDevINA2XX::kRegTempLimit = 0x10
staticprotected

Temperature Over-Limit Threshold (16-bit, R/W)

◆ kRegVBus

const uint8_t sfDevINA2XX::kRegVBus = 0x05
staticprotected

Bus Voltage Measurement (24/16-bit, R)

◆ kRegVShunt

const uint8_t sfDevINA2XX::kRegVShunt = 0x04
staticprotected

Shunt Voltage Measurement (24/16-bit, R)

◆ kShuntCalMask

const uint16_t sfDevINA2XX::kShuntCalMask = 0x7FFF
staticprotected

SHUNT_CAL valid bits [14:0] (bit 15 reserved)

◆ kShuntTempCoMask

const uint16_t sfDevINA2XX::kShuntTempCoMask = 0x3FFF
staticprotected

TEMPCO field mask, bits [13:0].


The documentation for this class was generated from the following files: