TMC5160 Driver
API reference
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
tmc51x0::UartCommInterface< Derived > Class Template Reference

CRTP-based UART implementation of TMC5160CommInterface. More...

#include <tmc51x0_comm_interface.hpp>

Inheritance diagram for tmc51x0::UartCommInterface< Derived >:
[legend]
Collaboration diagram for tmc51x0::UartCommInterface< Derived >:
[legend]

Public Member Functions

 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
 
- Public Member Functions inherited from tmc51x0::CommInterface< Derived >
 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.
 

Protected Member Functions

 ~UartCommInterface ()=default
 Protected destructor.
 
 UartCommInterface (UartCommInterface &&)=default
 
UartCommInterface & operator= (UartCommInterface &&)=default
 
- Protected Member Functions inherited from tmc51x0::CommInterface< Derived >
void DebugLog (int level, const char *tag, const char *format, va_list args) noexcept
 Debug logging function for detailed debugging information.
 
 ~CommInterface ()=default
 Protected destructor.
 
 CommInterface (CommInterface &&)=default
 
CommInterface & operator= (CommInterface &&)=default
 

Detailed Description

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:

Pin Functions in UART Mode

In UART mode (SD_MODE=0, SPI_MODE=0), certain pins take on special functions:

UART Daisy Chaining

The TMC5160 supports daisy chaining up to 255 nodes in UART mode:

UART Write Access Datagram (9 bytes per datasheet section 5.1.1):

UART Read Access Request (5 bytes per datasheet section 5.1.2):

UART Read Access Reply (9 bytes per datasheet section 5.1.2):

CRC8: CRC8-ATM polynomial (x^8 + x^2 + x^1 + x^0 = 0x07)

Baud Rate (per datasheet section 5.1.1):

Communication Reset (per datasheet section 5.1.1):

SENDDELAY (per datasheet section 5.1.2):

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
DerivedThe derived class type (CRTP pattern)

Constructor & Destructor Documentation

◆ UartCommInterface() [1/3]

template<typename Derived >
tmc51x0::UartCommInterface< Derived >::UartCommInterface ( )
inlinenoexcept

Construct UART communication interface with pin active level configuration.

Parameters
en_active_levelPhysical GPIO level for EN pin when ACTIVE (true=HIGH, false=LOW)
dir_active_levelPhysical GPIO level for DIR pin when ACTIVE (true=HIGH, false=LOW)
step_active_levelPhysical GPIO level for STEP pin when ACTIVE (true=HIGH, false=LOW)
Note
Multiple TMC5160 instances can share one UartCommInterface on the same UART bus. The node address is passed per transaction via ReadRegister() and WriteRegister() methods.

◆ ~UartCommInterface()

template<typename Derived >
tmc51x0::UartCommInterface< Derived >::~UartCommInterface ( )
protecteddefault

Protected destructor.

◆ UartCommInterface() [2/3]

template<typename Derived >
tmc51x0::UartCommInterface< Derived >::UartCommInterface ( UartCommInterface< Derived > &&  )
protecteddefault

◆ UartCommInterface() [3/3]

template<typename Derived >
tmc51x0::UartCommInterface< Derived >::UartCommInterface ( const UartCommInterface< Derived > &  )
delete

Member Function Documentation

◆ GetMode()

template<typename Derived >
CommMode tmc51x0::UartCommInterface< Derived >::GetMode ( ) const
inlinenoexcept

Get communication mode (always UART for this interface)

Returns
CommMode::UART

◆ GetNaoPin()

template<typename Derived >
Result< bool > tmc51x0::UartCommInterface< Derived >::GetNaoPin ( )
inlinenoexcept

Read NAO (Next Address Output) pin state.

Returns
Result<bool> containing true if NAO is active, false otherwise

NAO is the output from one TMC5160 that connects to the next TMC5160's NAI input in a daisy chain.

  • NAO is the SDO_CFG0 pin (pin 16) in UART mode
  • After programming a chip to its target address, NAO must be LOW to enable the next chip in the chain
  • NAO HIGH: Next chip is not yet accessible
  • NAO LOW: Next chip is accessible for programming

Default implementation delegates to derived class. Override for hardware-specific NAO pin reading.

Note
In UART mode, SD_MODE=0 and SPI_MODE=0 must be set
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

template<typename Derived >
UartCommInterface & tmc51x0::UartCommInterface< Derived >::operator= ( const UartCommInterface< Derived > &  )
delete

◆ operator=() [2/2]

template<typename Derived >
UartCommInterface & tmc51x0::UartCommInterface< Derived >::operator= ( UartCommInterface< Derived > &&  )
protecteddefault

◆ ReadRegister()

template<typename Derived >
Result< uint32_t > tmc51x0::UartCommInterface< Derived >::ReadRegister ( uint8_t  address,
uint8_t  node_address = 0 
)
inlinenoexcept

Read a 32-bit register via UART.

Parameters
addressRegister address (0x00-0x73)
valueReference to store the read value
node_addressUART node address (0-255; NODECONF.NODEADDR is 8 bits)
Returns
Result<uint32_t> containing the value or error
Here is the call graph for this function:

◆ SetNaiPin()

template<typename Derived >
Result< void > tmc51x0::UartCommInterface< Derived >::SetNaiPin ( bool  active)
inlinenoexcept

Set NAI (Next Address Input) pin state for daisy chaining.

Parameters
activetrue to set NAI active (high), false to set inactive (low)
Returns
Result<void> indicating success or error

For UART daisy chaining, NAI controls the addressing sequence.

  • NAI is the SDI_CFG1 pin (pin 15) in UART mode
  • When NAI is active (high), the node address increments by one
  • First chip in chain: NAI should be tied to GND (low) → responds to address 0
  • Subsequent chips: NAI connected to previous chip's NAO

Default implementation delegates to derived class. Override for hardware-specific NAI pin control.

Note
In UART mode, SD_MODE=0 and SPI_MODE=0 must be set
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UartReceive()

template<typename Derived >
Result< void > tmc51x0::UartCommInterface< Derived >::UartReceive ( uint8_t *  data,
size_t  length 
)
inlinenoexcept

Receive raw bytes via UART.

Parameters
dataPointer to buffer to store received bytes
lengthNumber of bytes to receive
Returns
Result<void> indicating success or error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UartSend()

template<typename Derived >
Result< void > tmc51x0::UartCommInterface< Derived >::UartSend ( const uint8_t *  data,
size_t  length 
)
inlinenoexcept

Send raw bytes via UART.

Parameters
dataPointer to data bytes to send
lengthNumber of bytes to send
Returns
Result<void> indicating success or error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteRegister()

template<typename Derived >
Result< void > tmc51x0::UartCommInterface< Derived >::WriteRegister ( uint8_t  address,
uint32_t  value,
uint8_t  node_address = 0 
)
inlinenoexcept

Write a 32-bit register via UART.

Parameters
addressRegister address (0x00-0x73)
value32-bit value to write
node_addressUART node address (0-255; NODECONF.NODEADDR is 8 bits)
Returns
Result<void> indicating success or error
Here is the call graph for this function:

The documentation for this class was generated from the following file: