as5048a-async
Async Rust driver for the AS5048A 14-bit magnetic rotary position sensor using the SPI interface.
This driver is designed for embedded systems using embedded-hal-async and works seamlessly with async runtimes like Embassy.
- Fully async using embedded-hal-asynctraits
- 14-bit angular position reading (0.022° resolution)
- Optional defmtlogging for debugging
- no_stdcompatible
- forbid(unsafe_code)- 100% safe Rust
AS5048A Requirements
The AS5048A is a 14-bit rotary position sensor with SPI interface:
- Resolution: 14-bit (16384 positions, 0.022°/LSB)
- SPI Mode: Mode 1 (CPOL=0, CPHA=1)
- Max Clock: 10 MHz (recommend 1-3 MHz for initial testing)
- Supply: 3.3V or 5V
For more details read the full AS5048A Datasheet.
Installation
Add to your Cargo.toml:
[]
 = "0.1"
 = "1.0"
Usage
Quick Start
use As5048a;
// Create sensor with an SpiDevice (bus + CS pin)
let mut sensor = new;
// Read angle (0-16383, representing 0-360°)
let angle = sensor.angle.await?;
let degrees =  * 360.0 / 16384.0;
For complete examples see the examples folder.
Diagnostics and Error Handling
// Check magnetic field strength and sensor status
let diag = sensor.diagnostics.await?;
if diag.is_valid 
// Clear error flags
sensor.clear_error_flag.await?;
API Reference
See the API documentation for complete details on available methods and types.
Main methods:
- angle()- Read 14-bit angle (0-16383)
- angle_degrees()- Read angle in degrees (0-359) using integer math
- magnitude()- Read CORDIC magnitude
- diagnostics()- Read diagnostics with AGC value and status flags
- clear_error_flag()- Clear error flag
Constants:
- ANGLE_MAX- Maximum angle value (16384) for custom conversions
MSRV (Minimum Supported Rust Version)
This crate requires Rust 1.87 or later.
Resources
Inspired by
Contributing
Contributions are welcome! Please run cargo test and cargo clippy before submitting.