AS8510-rs
A #![no_std] async Rust driver for the AS8510 current and voltage sensor, designed for embedded systems using the embedded-hal-async SPI interface. This crate provides an easy-to-use API to read bi-directional current and voltage measurements with configurable gain settings.
The AS8510 is a high-precision data acquisition IC commonly used in automotive and industrial applications for current sensing over a shunt resistor and voltage measurements.
Features
- Asynchronous API using
embedded-hal-asyncfor SPI communication. - Supports configurable current gain:
Gain1,Gain25,Gain40,Gain100. - Supports configurable voltage gain:
Gain25,Gain40. - Current measurement ranges:
Gain1: +2076A / -1523AGain25: ±400AGain40: ±235AGain100: ±77A
#![no_std]compatible for bare-metal embedded environments.- Error handling for SPI communication and device status.
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0"
= "1.0"
Ensure your target platform provides an implementation of embedded_hal_async::spi::SpiDevice.
Usage
Below is an example using the esp-hal crate for an ESP32-based setup. Adjust the SPI configuration and runtime according to your hardware and executor (e.g., embassy_executor).
use ;
use ;
use Duration;
async
Key Methods
new(peri, current_gain, voltage_gain): Initializes the AS8510 with the specified SPI device and gain settings.get_current(): Reads the current in amperes (A) asynchronously.get_voltage(): Reads the voltage (unverified implementation).
Gain Configuration
| Gain | Current Range (A) | Voltage Range |
|---|---|---|
Gain1 |
+2076 / -1523 | Not supported |
Gain25 |
±400 | Supported |
Gain40 |
±235 | Supported |
Gain100 |
±77 | Not supported |
Note: Voltage measurements are restricted to Gain25 and Gain40.
Dependencies
embedded-hal-async: For async SPI operations.
License
This crate is licensed under either of:
at your option.
Contributing
Contributions are welcome! Please submit issues or pull requests to the GitHub repository.
Notes
- The
get_voltage()method is currently unverified and may require additional calibration or validation. - Ensure your SPI device is configured correctly for the AS8510's requirements (e.g., 1 MHz frequency, Mode 1).