hart-rs
A no_std HART protocol implementation for embedded systems, written in Rust.
What it is
HART (Highway Addressable Remote Transducer) is an industrial protocol layered
over a 4-20 mA current loop. This workspace implements the full protocol stack
— codec, modem driver, and async master — as three no_std crates targeting
embedded microcontrollers such as the STM32H7 with an AD5700-1 HART modem.
Crate architecture
hart-protocol (codec: encode, decode, typed commands)
^
|
ad5700 (AD5700-1 modem driver: blocking + async)
^
|
embassy-hart (async HART master via Embassy + embassy-time)
hart-protocol is a standalone codec with no hardware dependencies.
ad5700 wraps the modem with embedded-hal traits and uses hart-protocol.
embassy-hart builds on ad5700's async driver and adds timeout management.
Supported commands
Universal read commands
| Cmd | Description |
|---|---|
| 0 | Read unique identifier (device ID) |
| 1 | Read primary variable |
| 2 | Read loop current and percent range |
| 3 | Read dynamic variables |
Common-practice read commands
| Cmd | Description |
|---|---|
| 9 | Read device variables with status |
| 11 | Read unique identifier by tag |
| 12 | Read message |
| 13 | Read tag, descriptor, and date |
| 14 | Read primary variable transducer info |
| 15 | Read device info |
| 16 | Read final assembly number |
| 20 | Read long tag |
| 48 | Read additional device status |
Write commands
| Cmd | Description |
|---|---|
| 6 | Write polling address |
| 17 | Write message |
| 18 | Write tag, descriptor, and date |
| 19 | Write final assembly number |
| 22 | Write long tag |
| 38 | Reset configuration changed flag |
Quick start
Encode a Command 0 request frame and decode a response using hart-protocol
(no hardware or I/O involved):
use encode_frame;
use Decoder;
use ;
use ;
use ;
use MIN_PREAMBLE_COUNT;
// --- Encode a Command 0 request ---
let address = Short ;
let req = ReadDeviceIdRequest;
let mut data_buf = ;
let data_len = req.encode_data.unwrap;
let mut frame_buf = ;
let frame_len = encode_frame.unwrap;
// frame_buf[..frame_len] is ready to send to the modem.
// --- Decode a Command 0 response byte-by-byte ---
let raw_response: & = &;
let mut decoder = new;
let mut raw_frame = None;
for &byte in raw_response
if let Some = raw_frame
Hardware target
This stack is designed for the STM32H7 microcontroller paired with the
Analog Devices AD5700-1 HART modem. The ad5700 and embassy-hart crates
depend on embedded-hal and Embassy respectively, keeping the codec
(hart-protocol) portable to any platform.
Releasing
- Update version in root
Cargo.toml([workspace.package] version = "X.Y.Z") - Commit:
release: vX.Y.Z - Tag:
git tag vX.Y.Z - Push:
git push && git push --tags
CI will verify tests pass, check the tag matches Cargo.toml, and publish all crates to crates.io in dependency order.
Requires CARGO_REGISTRY_TOKEN secret in GitHub repository settings.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.