Skip to content

Latest commit

 

History

37 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI Build Status

embedded-hal embedded-hal

License: MIT OR Apache-2.0

INA238

A platform-agnostic `#![no_std]` Rust driver for the Texas Instruments "INA238" 85V, 16-Bit High-Precision Power/Current/Voltage Monitor using `embedded-hal`.

More about INA238(../ina238/Docs/ina238.pdf)

Features

  • #![no_std] Support: Suitable for bare-metal microcontrollers (STM32, RP2040, ESP32, nRF, etc.).
  • embedded-hal Integration: Works with any I2C peripheral implementing embedded-hal 1.0 traits.
  • Core Telemetry:
    • Bus Voltage Measurement
    • Shunt Voltage Measurement
    • Calculated Current and Power Readings
    • Temperature Sensing
  • Configuration & Calibration:
    • Custom Shunt Resistor (SHUNT_CAL) calibration setup
    • Adjustable conversion times and averaging settings
  • Diagnostics & Alerts:
    • Full read access to diagnostic flags (DIAG_ALRT)
    • Configurable overvoltage, undervoltage, power, and temperature threshold limits (Setters & Getters)
  • Tested & Verified: Covered by unit tests using embedded-hal-mock to ensure accurate byte sequencing and register interaction logic.

Getting Started

Add ina238 to your Cargo.toml:

[dependencies]
ina238 = "0.1.0"

Example

use embedded_hal::i2c::I2c;
use ina238::Ina238;

// Create driver instance with default I2C address (0x40)
let mut sensor = Ina238::new(i2c, 0x40);

// Configure shunt calibration (e.g., for 2A max current & 10 mΩ shunt)
sensor.calibrate(2.0, 0.1).unwrap();

// Read bus voltage in Volts
if let Ok(bus_voltage) = sensor.bus_voltage() {
    // Process bus voltage...
}

// Read current in Amperes
if let Ok(current) = sensor.current() {
    // Process current...
}

Supports

  • Basic Telemetry (Bus Voltage, Shunt Voltage, Current, Power, Temperature)
  • Core Configuration and Calibration
  • Diagnostic & Alert Mask Registers (DIAG_ALRT)
  • Alert Threshold Limits (SOVL, SUVL, BOVL, BUVL, TOL, POL)
  • Async support

Functional API features:

  • Core Telemetry & Monitoring API

    • bus_voltage(), shunt_voltage(), current(), power(), die_temperature()
  • Configuration & Calibration API

    • set_config(), set_adc_config(), set_shunt_calibrate()
  • Threshold API

    • Threshold Setters: set_shunt_overvoltage_th(), set_shunt_undervoltage_th(), set_bus_overvoltage_th(), set_bus_undervoltage_th(), set_temperature_limit(), set_power_limit()

    • Threshold Getters: get_shunt_overvoltage_th(), get_shunt_undervoltage_th(), get_bus_overvoltage_th(), get_bus_undervoltage_th(), get_temp_overlimit(), get_power_overlimit()

  • Status & Alert Config: diag_flags(), set_alert_config()

  • Device Identification & Maintenance API

    • manufacture_id(), device_id(), reset()

Testing

This crate includes a unit test suite covering register reads, writes, and bitwise operations using embedded-hal-mock. Run the tests on your host platform with:

cargo test

License

Licensed under either of:

at your option.

About

A Rust driver for the INA238 current/voltage/power monitor IC.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages