ina226
I²C API for INA226 High-Side or Low-Side Measurement, Bi-Direcional Current and Power Monitor
ina226 Datasheet
Description
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 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
Example
To use the driver, you must have a concrete implementation of the embedded-hal traits. This example uses stm32f4xx-hal:
let mut i2c = dp.I2C1.i2c;
let mut ina_device = new;
match ina_device.search_ina_address ;
let mut ina_device = match ina_device.initialize ;
ina_device
.set_ina_mode
.set_ina_average
.set_ina_vbusct
.set_ina_vscht
.commit;
ina_device.set_ina_calibration_value.commit;
rprintln!;
rprintln!;
rprintln!;
rprintln!;
License
Licensed under either of
-
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
-
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.