|
| | UartCommInterface () noexcept |
| | Construct UART communication interface with pin active level configuration.
|
| |
| CommMode | GetMode () const noexcept |
| | Get communication mode (always UART for this interface)
|
| |
| Result< void > | SetNaiPin (bool active) noexcept |
| | Set NAI (Next Address Input) pin state for daisy chaining.
|
| |
| Result< bool > | GetNaoPin () noexcept |
| | Read NAO (Next Address Output) pin state.
|
| |
| Result< void > | UartSend (const uint8_t *data, size_t length) noexcept |
| | Send raw bytes via UART.
|
| |
| Result< void > | UartReceive (uint8_t *data, size_t length) noexcept |
| | Receive raw bytes via UART.
|
| |
| Result< uint32_t > | ReadRegister (uint8_t address, uint8_t node_address=0) noexcept |
| | Read a 32-bit register via UART.
|
| |
| Result< void > | WriteRegister (uint8_t address, uint32_t value, uint8_t node_address=0) noexcept |
| | Write a 32-bit register via UART.
|
| |
| | UartCommInterface (const UartCommInterface &)=delete |
| |
| UartCommInterface & | operator= (const UartCommInterface &)=delete |
| |
| | CommInterface () noexcept=default |
| | Construct communication interface.
|
| |
| CommMode | GetMode () const noexcept |
| | Get the underlying communication mode used by this interface.
|
| |
| Result< uint32_t > | ReadRegister (uint8_t address, uint8_t address_param=0) noexcept |
| | Read a 32-bit register from the TMC5160.
|
| |
| Result< void > | WriteRegister (uint8_t address, uint32_t value, uint8_t address_param=0) noexcept |
| | Write a 32-bit register to the TMC5160.
|
| |
| Result< void > | GpioSet (TMC51x0CtrlPin pin, GpioSignal signal) noexcept |
| | Set GPIO pin signal state (output control)
|
| |
| Result< GpioSignal > | GpioRead (TMC51x0CtrlPin pin) noexcept |
| | Read GPIO pin signal state (input state)
|
| |
| Result< void > | GpioSetActive (TMC51x0CtrlPin pin) noexcept |
| | Set GPIO pin to active state (convenience method)
|
| |
| Result< void > | GpioSetInactive (TMC51x0CtrlPin pin) noexcept |
| | Set GPIO pin to inactive state (convenience method)
|
| |
| void | DelayMs (uint32_t ms) noexcept |
| | Delay execution for specified milliseconds.
|
| |
| void | DelayUs (uint32_t us) noexcept |
| | Delay execution for specified microseconds.
|
| |
| Result< void > | SetPowerEnabled (bool enabled) noexcept |
| | Enable/disable power to the TMC51x0 (optional)
|
| |
| Result< void > | PowerCycle (uint32_t power_off_ms=20, uint32_t power_on_settle_ms=20) noexcept |
| | Power-cycle the TMC51x0 (optional)
|
| |
| Result< void > | SetClkFreq (uint32_t frequency_hz) noexcept |
| | Set external clock frequency on CLK pin (optional)
|
| |
| | CommInterface (const CommInterface &)=delete |
| |
| CommInterface & | operator= (const CommInterface &)=delete |
| |
| void | LogDebug (int level, const char *tag, const char *format,...) noexcept |
| | Public debug logging wrapper for external classes.
|
| |
| void | LogDebug (LogLevel level, const char *tag, const char *format,...) noexcept |
| | LogDebug overload that accepts the driver-native LogLevel enum.
|
| |
template<typename Derived>
class tmc51x0::UartCommInterface< Derived >
CRTP-based UART implementation of TMC5160CommInterface.
Uses UART single wire interface per datasheet section 5.1. Uses UART_TXD and UART_RXD signals; supports external transceivers via UART_TXEN. Each byte is transmitted LSB...MSB, highest byte transmitted first.
UART Mode Requirements
For UART operation, the TMC5160 must be configured with:
- SD_MODE (pin 21): Must be LOW (0)
- SPI_MODE (pin 22): Must be LOW (0)
- When both are LOW, UART operation is enabled
Pin Functions in UART Mode
In UART mode (SD_MODE=0, SPI_MODE=0), certain pins take on special functions:
- SDI_CFG1 (pin 15) → NAI (Next Address Input): Input for address selection
- SDO_CFG0 (pin 16) → NAO (Next Address Output): Output that connects to next chip's NAI
- DIAG0_SWN (pin 26) → SWION (Single Wire I/O Negative): UART single wire interface
- DIAG1_SWP (pin 27) → SWIOP (Single Wire I/O Positive): UART single wire interface
UART Daisy Chaining
The TMC5160 supports daisy chaining up to 255 nodes in UART mode:
- First chip: NAI tied to GND → responds to address 0
- Each chip's NAO connects to the next chip's NAI
- After programming each chip, its NAO must be LOW to enable the next chip
- Program chips sequentially starting from address 0
- See datasheet section 5.4 for detailed addressing procedure
UART Write Access Datagram (9 bytes per datasheet section 5.1.1):
- Byte 0: Sync nibble (bits 0-3: 1,0,1,0) + Reserved (bits 4-7) + NODEADDR (8 bits)
- Sync pattern enables baud rate synchronization
- Reserved bits are don't cares but included in CRC
- Byte 1: RW bit (bit 8 = 1 for write) + 7-bit register address
- Bytes 2-5: 32-bit data (high byte to low byte, MSB-first)
- Bytes 6-7: Reserved (don't cares but included in CRC)
- Byte 8: CRC8 checksum (CRC8-ATM polynomial 0x07, LSB to MSB)
UART Read Access Request (5 bytes per datasheet section 5.1.2):
- Byte 0: Sync nibble + Reserved + NODEADDR
- Byte 1: RW bit (bit 8 = 0 for read) + 7-bit register address
- Bytes 2-3: Reserved (don't cares but included in CRC)
- Byte 4: CRC8 checksum
UART Read Access Reply (9 bytes per datasheet section 5.1.2):
- Byte 0: Sync nibble + Reserved (0) + 0xFF (address code for master)
- Byte 1: Register address (0)
- Bytes 2-5: 32-bit data (high byte to low byte, MSB-first)
- Bytes 6-7: Reserved (0)
- Byte 8: CRC8 checksum
CRC8: CRC8-ATM polynomial (x^8 + x^2 + x^1 + x^0 = 0x07)
- Applied LSB to MSB, including sync and addressing byte
- Sync nibble is assumed to always be correct
Baud Rate (per datasheet section 5.1.1):
- Minimum: 9000 baud (assuming 20 MHz clock)
- Maximum: fCLK/16
- Automatically detected from sync frame timing
- Bit time calculated from start bit (1 to 0 transition) to end of sync frame
Communication Reset (per datasheet section 5.1.1):
- Pause time > 63 bit times between start bits resets communication
- Minimum 12 bit times bus idle time required after reset
- Glitches (< 16 clock cycles) cause 12 bit time timeout
SENDDELAY (per datasheet section 5.1.2):
- Programmable delay after read request before reply (multiples of 8 bit times)
- Default: 8 bit times
- Multi-node systems: Set SENDDELAY to minimum 2 for all nodes
Example usage:
class MyUART : public tmc5160::UartCommInterface<MyUART> {
public:
CommMode mode() const noexcept {
return CommMode::UART; }
bool uartSend(...) { ... }
bool uartReceive(...) { ... }
bool gpioSet(...) { ... }
bool gpioRead(...) { ... }
void debugLog(...) { ... }
void delayMs(...) { ... }
void delayUs(...) { ... }
};
CommMode
Supported physical communication modes for TMC51x0.
Definition tmc51x0_comm_interface.hpp:221
- Template Parameters
-
| Derived | The derived class type (CRTP pattern) |