Crate ina226_tp

source ·
Expand description

Rust Driver for device INA226 High-Side or Low-Side Measurement, Bi-Direcional Current and Power Monitor

Datasheet: INA226

This crate was made for and tested on INA226 from Texas Instruments, it is based on I2C from embedded-hal crate. The implementation of this crate is based on #![no_std] but with some minor adjustments it can be used on std environments. This crate is async compatible (must enable ‘async’ feature).

This driver allows you to:

  • Manually configure INA226 address
  • Automatically detect INA226 address
  • Fully configure the configuration register
  • Calibrate the device
  • Manually configure the Mask/Enable register
  • Manually configure the Alert register
  • Read Voltage, shunt voltage, current and power
  • Test device connection for errors
  • Reset the device to factory specs

This driver contains two modes, non operational and operational: Non Operational:

  • When creating the device it starts on this mode
  • you can manualy set the address or auto detect it
  • when initializing the device it will test the connection and then move to Operational mode.

Operational:

  • Set configuration, mask/enable and alert registers
  • Set the calibration register based on Rshunt and MaxAmp (set_ina_calibration)
  • Set the calibration register manually (set_ina_calibration_value)
  • Read configured values
  • Reset the device to factory specs
  • Read voltage, shunt voltage, current and power

Please note that after any configuration change, a commit operation must be performed so the information can be sent to the IC.

If the device is not calibrated, it assumes a shunt resistor value of 2 mOhms and maximum current of 10 Amps

Note on I2C usage: If you need to search for INA Address, then you must use the BUS version of I2C from Embedded hal because you will need to pass an I2C instance for the NEW and another for the INITIALIZE Methods. If you don’t need to search for INA Address, then pass NONE to the NEW method and then the I2C instance for INITIALIZE method.

Structs§

  • ina226 register data
  • ina226 requiring address and connection test
  • ina226 in operational mode (connection tested and functional)

Enums§

  • Valid error codes
  • Enum used to determine the number of averages to be used
  • Used to set the ina226 mode of operation
  • Set the conversion time for the Bus voltage measurement
  • Set the conversion time for the Shunt Bus voltage measurement
  • Used to choose the function of alert pin
  • Enum used for ina226 addressing based on pin connection

Functions§

  • Function that converts physical pin address connection to respective hexadecimal value