Crate ask433

Source
Expand description

§ask433

A portable, no_std Rust driver for Amplitude Shift Keying (ASK/OOK) 433 MHz RF transceivers, compatible with cheap modules like the FS1000A and XY-MK-5V.

This driver implements a software-based ASK modem using:

  • embedded-hal traits for digital I/O and timing
  • a software PLL for reception and demodulation
  • interrupt-safe buffer access with critical-section
  • optional tick sources using either timer interrupts or blocking delay

§Crate features

FeatureDescription
stdDisables #![no_std] support and replaces healpess::Vecs with
std::vec::Vecs
delay-loopUses embedded_hal::blocking::delay::DelayUs for bit timing
timer-isr (default)Uses critical_section::with for bit timing
defmtUses defmt logging
logUses log logging

§Software Features

  • Transmitter and receiver in pure software (no UART or DMA)
  • Bit-level protocol compatible with RadioHead RH_ASK
  • Supports training preamble, 4b6b encoding, and CRC16 validation
  • Fully portable across AVR (e.g., Arduino Uno) and ARM Cortex-M targets
  • Feature flags for interrupt-driven or blocking tick scheduling

§Usage

use ask433::driver::AskDriver;
fn main() {
    // ...
    let mut driver: AskDriver<Pin, Pin, Pin> = AskDriver::new(tx_pin, rx_pin, None, 8, None, None);
                                                       // ^ this is the number of interrupts per bit
    loop {
        driver.tick(); // Call at ~62.5 µs intervals
    }
}

Or, use run_tick_loop() with a DelayUs implementation:

use ask433::driver::AskDriver;
#[cfg(feature = "delay-loop")]
use ask433::timer::run_ask_tick_loop;

fn main() {
    // ...
    let mut driver: AskDriver<Pin, Pin, Pin> = AskDriver::new(tx_pin, rx_pin, None, 8, None, None);
    run_ask_tick_loop(&mut driver, &mut delay, 63);
}

§Feature Flags

  • timer-isr: Use a hardware timer ISR to call tick() (requires platform-specific ISR setup)
  • delay-loop: Use a blocking loop to drive tick() with embedded_hal::blocking::delay::DelayUs

§Integration Notes

  • Transmit and receive timing are based on ~2 kbps bit rate (~62.5 µs per tick)
  • Timing precision is critical; hardware timer configuration is recommended for reliability
  • Only one driver instance should be active at a time in interrupt-driven mode

§Status

This crate is in early development. Contributions welcome!

– Designed for #![no_std] use in resource-constrained embedded environments.

Re-exports§

pub use critical_section;
pub use heapless;

Modules§

consts
Constants used across the ASK protocol implementation.
driver
ASK/OOK modem driver for 433 MHz RF transceivers.
encoding
4b6b symbol encoding and decoding for ASK/OOK message framing.
pll
Software PLL for ASK/OOK signal demodulation.
timer
Timer and tick-loop utilities for ASK driver.

Macros§

init_ask_driver
Declares a static global ASK_DRIVER instance protected by a critical_section mutex.
receive_from_ask
Attempts to receive a completed message from the global ASK driver instance.
send_from_ask
Sends a message from the global ASK driver using a heapless Vec<u8>.
setup_ask_driver
Initializes the global ASK_DRIVER singleton with a new driver instance.
tick_ask_timer
Calls tick() on the global ASK_DRIVER if it has been initialized.