INA233 - Bidirectional current and power monitor

Description

Library for interfacing Texas Instruments INA233 bidirectional Current and Power Monitor IC with I2C interface

The INA233 is a current, voltage, and power monitor with an I2C interface. -) I2C interface with communication speed up to 400 kHz -) 16 user selectable addresses (chosen by chip pins) -) Integrated Power Accumulator for Energy and Average Power Monitoring -) Configurable Averaging Options -) Independent Alert Limits for Current, Bus Voltage, and Power

OVERVIEW

INA233_Abstract:
This library can be used to handle Texas Instruments INA233 bidirectional current and power monitor IC.

Interfaces: 1x I2C

The INA233 is a current, voltage, and power monitor with an I2C interface.
  • I2C interface with communication speed up to 400 kHz
  • 16 user selectable addresses (chosen by chip pins)
  • Integrated Power Accumulator for Energy and Average Power Monitoring
  • Configurable Averaging Options
  • Independent Alert Limits for Current, Bus Voltage, and Power
  • INA233_How_to_use:
    /* Hardware setup */ const { PORT_I2C = 0, // The first I2C interface should be used. CHIP_ADDR = INA233_I2C_ADR0, // I2C Address of the chip // (depends on the logic level at the chip's A0 and A1 pins) R_SHUNT = 25, // Shunt resistor connected between the IN+ and IN- pins of the INA233 [mOhm] } /* Handles for available sensors */ new hINA[TINA233_Handle]; // Handle to manage the INA233 /* 1 sec. timer is used for the general program sequence */ #callback MainTimer() { new vin; // Input/Bus Voltage read from the INA233 [mV] new iin; // Input Current read from the INA233 [uA] catch(INA233_ReadVIn(hINA, vin)); // Reads Input/Bus Voltage ​​from the INA233 #watch("vin=%dmV", vin); // Issues Input/Bus Voltage via the watch panel // Calculates the input current based on the shunt voltage read from the INA233 // and shunt resistor value. catch(INA233_ReadIIn(hINA, R_SHUNT, iin)); if(iin > 10000) // If the input current is >10mA -> #watch("iin=%.2fmA", iin / 1000.0); // Issues the input current in mA else // Otherwise -> #watch("iin=%duA", iin); // Issues the input current in mA } /* Application entry point */ main() { // Inits the I2C interface catch( rM2M_I2cInit( PORT_I2C, INA233_CLOCK, 0)); // Initializes i2c communication with the INA233 and prepares the INA233 for use catch(INA233_Init(hINA, PORT_I2C, CHIP_ADDR)); // Activates the INA233 using the following configuration: // Continuous measurement for Shunt and Bus Voltage (Power-On Default) // Conversion Time is 1.1ms (Power-On Default) // 4 samples will be averaged (Power-On Default = 1) new config = INA233_CFG_MODE_VSH_VBUS_CONT | INA233_CFG_VSHCT_1_1MS | INA233_CFG_VBUS_1_1MS | INA233_CFG_AVG_4; catch(INA233_Enable(hINA, config)); // Initialisation of a cyclic sec. timer setInterval(MainTimer, 1000); }

    BASIC

    INA233_CLOCK -

    typical I2C clock speed to be used

    INA233_I2C_ADRx:

    Available I2C addresses

    The corresponding I2C address must be used if the condition applies:
    INA233_I2C_ADR0 - A0 = GND, A1 = GND
    INA233_I2C_ADR1 - A0 = GND, A1 = VS
    INA233_I2C_ADR2 - A0 = GND, A1 = SDA
    INA233_I2C_ADR3 - A0 = GND, A1 = SCL
    INA233_I2C_ADR4 - A0 = VS, A1 = GND
    INA233_I2C_ADR5 - A0 = VS, A1 = VS
    INA233_I2C_ADR6 - A0 = VS, A1 = SDA
    INA233_I2C_ADR7 - A0 = VS, A1 = SCL
    INA233_I2C_ADR8 - A0 = SDA, A1 = GND
    INA233_I2C_ADR9 - A0 = SDA, A1 = VS
    INA233_I2C_ADR10 - A0 = SDA, A1 = SDA
    INA233_I2C_ADR11 - A0 = SDA, A1 = SCL
    INA233_I2C_ADR12 - A0 = SCL, A1 = GND
    INA233_I2C_ADR13 - A0 = SCL, A1 = VS
    INA233_I2C_ADR14 - A0 = SCL, A1 = SDA
    INA233_I2C_ADR15 - A0 = SCL, A1 = SCL
    INA233_CFG_x:

    ADC Configuration (bitmasks for register MFR_ADC_CONFIG 0xD0)

  • Averaging modes (Bit 9-11) see INA233_CFG_AVG_x
  • Bus Voltage Conversion Time (Bit 6-8) see INA233_CFG_VBUS_x
  • Shunt Voltage Conversion Time (Bit 3-5) see INA233_CFG_VSHCT_x
  • Operating modes (Bit 0-2) see INA233_CFG_MODE_x
  • INA233_CFG_MODE_x:

    Available operating modes (MFR_ADC_CONFIG, Bit 0-2)

    INA233_CFG_MODE_SHUTDOWN - 0: Power-down (or shutdown)
    INA233_CFG_MODE_VSH_TRIG - 1: Shunt voltage, triggered
    INA233_CFG_MODE_VBUS_TRIG - 2: Bus voltage, triggered
    INA233_CFG_MODE_VSH_VBUS_TRIG - 3: Shunt and bus, triggered
    INA233_CFG_MODE_POWER_DOWN - 4: Power-down (or shutdown) (equals INA233_CFG_MODE_SHUTDOWN)
    INA233_CFG_MODE_VSHUNT_CONT - 5: Shunt voltage, continuous
    INA233_CFG_MODE_VBUS_CONT - 6: Bus voltage, continuous
    INA233_CFG_MODE_VSH_VBUS_CONT - 7: Shunt and bus, continuous (Default)
    When using one of the triggered modes writing the "MFR_ADC_CONFIG" register triggers the measurement. Thus, to trigger another single-shot conversion, the "MFR_ADC_CONFIG" register must be written to a second time, even if the mode does not change. Use the INA233_Enable() function to write the "MFR_ADC_CONFIG" register.
    INA233_CFG_VSHCT_x:

    Settings for Shunt Voltage Conversion Time (MFR_ADC_CONFIG, Bit 3-5)

    INA233_CFG_VSHCT_140US - (0 << 3): 140us
    INA233_CFG_VSHCT_204US - (1 << 3): 204us
    INA233_CFG_VSHCT_332US - (2 << 3): 332us
    INA233_CFG_VSHCT_588US - (3 << 3): 588us
    INA233_CFG_VSHCT_1_1MS - (4 << 3): 1.1ms (Default)
    INA233_CFG_VSHCT_2_116MS - (5 << 3): 2.116ms
    INA233_CFG_VSHCT_4_156MS - (6 << 3): 4.156ms
    INA233_CFG_VSHCT_8_244MS - (7 << 3): 8.244ms
    INA233_CFG_VBUS_x:

    Settings for Bus Voltage Conversion Time (MFR_ADC_CONFIG, Bit 6-8)

    INA233_CFG_VBUS_140US - (0 << 6): 140us
    INA233_CFG_VBUS_204US - (1 << 6): 204us
    INA233_CFG_VBUS_332US - (2 << 6): 332us
    INA233_CFG_VBUS_588US - (3 << 6): 588us
    INA233_CFG_VBUS_1_1MS - (4 << 6): 1.1ms (Default)
    INA233_CFG_VBUS_2_116MS - (5 << 6): 2.116ms
    INA233_CFG_VBUS_4_156MS - (6 << 6): 4.156ms
    INA233_CFG_VBUS_8_244MS - (7 << 6): 8.244ms
    INA233_CFG_AVG_x:

    Available averaging modes (MFR_ADC_CONFIG, Bit 9-11)

    INA233_CFG_AVG_1 - (0 << 9): no averaging (Default)
    INA233_CFG_AVG_4 - (1 << 9): average 4 samples
    INA233_CFG_AVG_16 - (2 << 9): average 16 samples
    INA233_CFG_AVG_64 - (3 << 9): average 64 samples
    INA233_CFG_AVG_128 - (4 << 9): average 128 samples
    INA233_CFG_AVG_256 - (5 << 9): average 256 samples
    INA233_CFG_AVG_512 - (6 << 9): average 512 samples
    INA233_CFG_AVG_1024 - (7 << 9): average 1024 samples
    INA233_Init(handle[TINA233_Handle], i2c, addr)

    Initializes i2c communication with the INA233 and prepares the INA233 for use


    Reads the manufacturer's ID and device number of the chip and checks if a chip supported by the library has been found.

    handle : TINA233_Handle - Empty device handle for a INA233
    i2c : s32 - I2C interface where INA233 is connected to
    addr : s32 - I2C Address of the chip (depends on the logic level at the chip's A0 and A1 pins)
    Use only the addresses specified under INA233_I2C_ADRx
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Manufacturer ID could not be read
  • Device number of the chip could not be read
  • Found chip not supported by the library
  • The selected I2C interface must be enabled (rM2M_I2cInit()) before calling INA233_Init.
  • INA233 is specified for I2C Fast-Mode (400kHz, use INA233_CLOCK).
  • The power-on default for INA233 is to convert shunt and bus voltage (see INA233_CFG_x definitions).
  • If power saving is required, INA233_Disable must be called after INA233_Init.
  • INA233_Enable(handle[TINA233_Handle], config)

    Activates the INA233 by setting the "MFR_ADC_CONFIG" register

    handle : TINA233_Handle - Device handle of a specific INA233 (Initialized by INA233_Init() )
    config : s32 - ADC Configuration (Averaging modes / Bus Voltage Conversion Time / Shunt Voltage Conversion Time / Operating modes )
    Use INA233_CFG_AVG_x | INA233_CFG_VBUS_x | INA233_CFG_VSHCT_x | INA233_CFG_MODE_x
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    INA233_ReadVIn(handle[TINA233_Handle], &vin)

    Reads the measured Input/Bus Voltage (i.e. voltage at VBUS pin) from the INA233

    handle : TINA233_Handle - Device handle of a specific INA233 (Initialized by INA233_Init() )
    vin : s32 - Buffer for storing Input/Bus Voltage [mV]
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    INA233_ReadIIn(handle[TINA233_Handle], rshunt, &iin)

    Calculates the input current based on the shunt voltage (i.e. voltage difference between IN+ and IN-) read from the INA233 and the transferred value of the shunt resistor.

    handle : TINA233_Handle - Device handle of a specific INA233 (Initialized by INA233_Init() )
    rshunt : S32 - Shunt Resistor Value [mOhm]
    iin : S32 - Buffer for storing Input Current [uA]
    Input Current is calculated based on provided rshunt value.
    returns : s32
    OK - If successful
    ERROR - If an error occurs
    INA233_Disable(handle[TINA233_Handle])

    Sets the INA233 into power-down mode (i.e. no measurements are performed) and thus grants minimum power consumption


    When accessing the MFR_ADC_CONFIG register, only the operating mode is set to "Power-down". All other bits of the MFR_ADC_CONFIG register remain unchanged.

    handle : TINA233_Handle - Device handle of a specific INA233 (Initialized by INA233_Init() )
    returns : s32
    OK - If successful
    ERROR - If an error occurs

    EXPERT

    INA233_CLOCK_MAX -

    absolute maximum I2C clock speed

    INA233_CMD_x:

    Available Commands (Command | R/W | Number of byte | Default | Description)

    INA233_CMD_CLEAR_FAULTS - 0x03 | Send byte | 0 | N/A |
    Clears the status registers and rearms the black box registers for updating
    INA233_CMD_RESTORE_DEFAULT_ALL - 0x12 | Send byte | 0 | N/A |
    Restores internal registers to the default values
    INA233_CMD_CAPABILITY - 0x19 | R | 1 | 0xB0 |
    Retrieves the device capability
    INA233_CMD_IOUT_OC_WARN_LIMIT - 0x4A | R/W | 2 | 0x7FF8 |
    Retrieves or stores the output overcurrent warn limit threshold
    INA233_CMD_VIN_OV_WARN_LIMIT - 0x57 | R/W | 2 | 0x7FF8 |
    Retrieves or stores the input overvoltage warn limit threshold
    INA233_CMD_VIN_UV_WARN_LIMIT - 0x58 | R/W | 2 | 0x0000 |
    Retrieves or stores the input undervoltage warn limit threshold
    INA233_CMD_PIN_OP_WARN_LIMIT - 0x6B | R/W | 2 | 0x7FF8 |
    Retrieves or stores the output overpower warn limit threshold
    INA233_CMD_STATUS_BYTE - 0x78 | R | 1 | 0x00 |
    Retrieves information about the device operating status
    INA233_CMD_STATUS_WORD - 0x79 | R | 2 | 0x1000 |
    Retrieves information about the device operating status
    INA233_CMD_STATUS_IOUT - 0x7B | R/W, CLR | 1 | 0x00 |
    Retrieves information about the output current status
    INA233_CMD_STATUS_INPUT - 0x7C | R/W, CLR | 1 | 0x00 |
    Retrieves information about the input status
    INA233_CMD_STATUS_CML - 0x7E | R/W, CLR | 1 | 0x00 |
    Retrieves information about the communications status
    INA233_CMD_STATUS_MFR_SPECIFIC - 0x80 | R/W, CLR | 1 | 0x20 |
    Retrieves information about the manufacturer specific device status
    INA233_CMD_READ_EIN - 0x86 | Block read | 6 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,|
    Retrieves the energy reading measurement
    INA233_CMD_READ_VIN - 0x88 | R | 2 | 0x0000 |
    Retrieves the measurement for the VBUS voltage (use INA233_ReadVIn() )
    INA233_CMD_READ_IIN - 0x89 | R | 2 | 0x0000 |
    Retrieves the input current measurement, supports both positive and negative currents
    INA233_CMD_READ_VOUT - 0x8B | R | 2 | 0x0000 |
    Mirrors READ_VIN
    INA233_CMD_READ_IOUT - 0x8C | R | 2 | 0x0000 |
    Mirror of READ_IN for compatibility
    INA233_CMD_READ_POUT - 0x96 | R | 2 | 0x0000 |
    Mirror of READ_PIN for compatibility with possible VBUS connections
    INA233_CMD_READ_PIN - 0x97 | R | 2 | 0x0000 |
    Retrieves the input power measurement
    INA233_CMD_MFR_ID - 0x99 | Block read | 2 | 0x54, 0x49 |
    Retrieves the manufacturer ID in ASCII characters (TI)
    INA233_CMD_MFR_MODEL - 0x9A | Block read | 6 | 0x49, 0x4E, 0x41, 0x32, 0x33, 0x33 |
    Retrieves the device number in ASCII characters (INA233)
    INA233_CMD_MFR_REVISION - 0x9B | R | 2 | 0x41, 0x30 |
    Retrieves the device revision letter and number in ASCII (for instance, A0)
    INA233_CMD_MFR_ADC_CONFIG - 0xD0 | R/W | 2 | 0x4127 |
    Configures the ADC averaging modes, conversion times, and operating modes (use INA233_Enable() )
    INA233_CMD_MFR_READ_VSHUNT - 0xD1 | R | 2 | 0x0000 |
    Retrieves the shunt voltage measurement
    INA233_CMD_MFR_ALERT_MASK - 0xD2 | R/W | 1 | 0xF0 |
    Allows masking of device warnings
    INA233_CMD_MFR_CALIBRATION - 0xD4 | R/W | 2 | 0x0001 |
    Allows the value of the current-sense resistor calibration value to be input. Must be programed at power-up. Default value is set to 1.
    INA233_CMD_MFR_DEVICE_CONFIG - 0xD5 | R/W | 1 | 0x02 |
    Allows the ALERT pin polarity to be changed
    INA233_CMD_CLEAR_EIN - 0xD6 | Send byte | 0 | N/A |
    Clears the energy accumulator
    INA233_CMD_TI_MFR_ID - 0xE0 | R | 2 | ASCII TI, 0x5449 |
    Returns a unique word for the manufacturer ID
    INA233_CMD_TI_MFR_MODEL - 0xE1 | R | 2 | ASCII 33 |
    Returns a unique word for the manufacturer model
    INA233_CMD_TI_MFR_REVISION - 0xE2 | R | 2 | ASCII A0 |
    Returns a unique word for the manufacturer revision
    Please see datasheet for more information.
    INA233_Com(handle[TINA233_Handle], aData{}, writeLen, readLen)

    Perform raw INA233 read/write access. Data is first of all sent and data is then received.

    handle : TINA233_Handle - Device handle of a specific INA233 (Initialized by INA233_Init() )
    aData : {} - Array in which the data to be sent must initially be saved. Once the data has been sent, the array is used as a memory for the data to be received.
    writeLen : s32 - Number of bytes to be sent
    readLen : s32 - Number of bytes to be received
    returns : s32
    OK - if successful
    ERROR - if one of the following errors occurs
  • Number of bytes to be sent >255
  • Number of bytes to be received >255
  • Another error occurs
  • Access to INA233 is always started by sending one byte command code (see INA233_CMD_x definitions) followed by a variable number of bytes to send and/or receive (depending on the selected command). Please see datasheet for more information.

    On this page

    INA233 - Bidirectional current and power monitor