Expand description
Async no_std driver for the Microchip / Atmel ATM90E32 3-phase
SPI power metering IC.
This crate provides a lightweight, portable driver built on top of
embedded-hal-async.
It has no dependency on any specific async runtime and works with
Embassy, RTIC2, or any other executor that implements
SpiDevice and
DelayNs.
§Architecture
The crate follows a sans-I/O split:
proto— pure functions: byte-frame building, response parsing, raw → engineering unit conversions, and the post-reset init sequence expressed as data. No I/O, no async — 100% host-testable.driver— async transport: owns the SPI device and delay, invokes theprotohelpers, maps errors, and sequences the init writes.
§Features
defmt(optional) — derivesdefmt::Formaton public types for ergonomic logging with thedefmtecosystem.
§Quick start
let mut meter = Atm90e32::new(spi, delay);
meter.probe().await?;
let cfg = Config::default()
.with_voltage_gain([39470, 39470, 39470])
.with_current_gain([65327, 65327, 65327])
.with_line_freq(LineFreq::Hz50)
.with_pga_gain(PgaGain::X2);
meter.init(&cfg).await?;
loop {
let r = meter.read_all_phases().await?;
// use r.voltage, r.current, r.power, r.reactive, r.pf, r.frequency
}§What’s implemented
The driver covers the measurement set used by production JetHome PM380 meters: RMS voltage/current, active and reactive power, power factor, mains frequency, phase angle, chip temperature, and phase status (overcurrent, overvoltage, voltage sag, phase loss) on all three phases. Not yet implemented (contributions welcome): energy accumulation, apparent power, harmonic analysis, zero-crossing interrupts, and ATM90E36 family support.
§License
Dual-licensed under either Apache-2.0 or GPL-2.0-or-later at the user’s option.
Re-exports§
pub use crate::config::Config;pub use crate::config::LineFreq;pub use crate::config::PgaGain;pub use crate::driver::Atm90e32;pub use crate::driver::Phase;pub use crate::error::Error;pub use crate::error::InitStage;pub use crate::readings::PhaseReadings;pub use crate::status::PhaseStatus;
Modules§
- config
- Initialization configuration for the ATM90E32.
- driver
- Async driver struct for the ATM90E32.
- error
- Error types returned by the driver.
- proto
- Sans-I/O helpers — pure functions with no SPI, no async, no delays.
- readings
- Measurement result types.
- registers
- ATM90E32 register address map.
- status
- Phase and frequency status decoded from the ATM90E32 EMM state registers.