Expand description
§TMC2209 Driver
A no_std Rust driver for the TMC2209 stepper motor driver.
This crate provides:
- Full register definitions for all 24 TMC2209 registers
- Type-safe register access with bitfield getters/setters
- High-level
Tmc2209driver struct for UART communication - Blocking API (feature
blocking) - Async API (feature
async) - Utility functions for current/velocity calculations
§Features
blocking(default): Enable blocking UART API usingembedded_iotraitsasync: Enable async UART API usingembedded_io_asynctraitsdefmt: Enabledefmt::Formatderives for debugging
§Example
ⓘ
use tmc2209::{Tmc2209, registers::{IholdIrun, Chopconf, MicrostepResolution}};
// Create driver with UART and slave address 0
let mut driver = Tmc2209::new(uart, 0);
// Check connection
if driver.is_connected() {
// Set motor current (run=16, hold=8)
driver.set_current(16, 8, 1)?;
// Set microstep resolution
driver.set_microsteps(MicrostepResolution::M16)?;
// Enable StealthChop for quiet operation
driver.enable_stealthchop()?;
// Start moving at velocity 1000
driver.set_velocity(1000)?;
}§Protocol Overview
The TMC2209 uses a simple UART protocol at 115200 baud (configurable):
- Read request: 4 bytes
[0x05, slave_addr, reg_addr, CRC] - Write request: 8 bytes
[0x05, slave_addr, reg_addr|0x80, data[3:0], CRC] - Read response: 8 bytes
[0x05, 0xFF, reg_addr, data[3:0], CRC]
The driver handles echo bytes automatically (TMC2209 echoes all sent data on its single-wire UART interface).
Re-exports§
pub use driver::Tmc2209;pub use error::Error;pub use registers::Address;pub use registers::Chopconf;pub use registers::Coolconf;pub use registers::DrvStatus;pub use registers::FactoryConf;pub use registers::Gconf;pub use registers::Gstat;pub use registers::Ifcnt;pub use registers::IholdIrun;pub use registers::Ioin;pub use registers::MicrostepResolution;pub use registers::Mscnt;pub use registers::Mscuract;pub use registers::OtpProg;pub use registers::OtpRead;pub use registers::Pwmconf;pub use registers::PwmAuto;pub use registers::PwmScale;pub use registers::ReadableRegister;pub use registers::Register;pub use registers::SgResult;pub use registers::Sgthrs;pub use registers::Slaveconf;pub use registers::StandstillMode;pub use registers::Tcoolthrs;pub use registers::Tpowerdown;pub use registers::Tpwmthrs;pub use registers::Tstep;pub use registers::Vactual;pub use registers::WritableRegister;pub use util::calculate_current_settings;pub use util::cs_to_current;pub use util::current_to_cs;pub use util::optimal_vsense;pub use util::tstep_to_velocity;pub use util::velocity_to_tpwmthrs;pub use util::velocity_to_vactual;pub use util::DEFAULT_FCLK;pub use util::DEFAULT_RSENSE;pub use datagram::ReadRequest;pub use datagram::ReadResponse;pub use datagram::ResponseReader;pub use datagram::WriteRequest;pub use datagram::MASTER_ADDR;pub use datagram::SYNC;