HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0::UartFrame Struct Reference

TMC5160 UART command/response frame structure with built-in CRC8. More...

#include <tmc51x0_comm_interface.hpp>

Collaboration diagram for tmc51x0::UartFrame:
[legend]

Classes

union  Frame
 Union for accessing UART frames in different ways. More...
 

Public Member Functions

size_t GetSize () const noexcept
 Get frame size in bytes based on type.
 
uint8_t GetAddress () const noexcept
 Get register address from frame.
 
bool IsWrite () const noexcept
 Check if this is a write frame.
 
uint32_t GetValue () const noexcept
 Get 32-bit data value from frame.
 
void CalculateCrc () noexcept
 Calculate and set CRC8 checksum for the frame CRC8 is calculated over all bytes except the CRC byte itself.
 
bool VerifyCrc () const noexcept
 Verify CRC8 checksum of the frame.
 
void SetFrame (const uint8_t *bytes, UartFrameType frame_type) noexcept
 Set the frame from raw bytes.
 
void GetFrame (uint8_t *bytes) const noexcept
 Get the frame as raw bytes.
 
bool IsValid () const noexcept
 Check if frame is valid.
 

Static Public Member Functions

static UartFrame Write (uint8_t node_addr, uint8_t reg_addr, uint32_t value) noexcept
 Construct a write access frame (8 bytes)
 
static UartFrame ReadRequest (uint8_t node_addr, uint8_t reg_addr) noexcept
 Construct a read request frame (4 bytes)
 
static UartFrame ReadReply (const uint8_t *bytes) noexcept
 Construct a read reply frame from received bytes (8 bytes)
 

Public Attributes

union tmc51x0::UartFrame::Frame frame
 
UartFrameType type
 Frame type.
 

Detailed Description

TMC5160 UART command/response frame structure with built-in CRC8.

Represents a TMC5160 UART frame per datasheet section 5.1. Supports write access (8 bytes), read request (4 bytes), and read reply (8 bytes). Automatically calculates and verifies CRC8 checksum.

Frame Structure (per datasheet section 5.1):

  • Write Access: Byte 0 (sync+rsv), Byte 1 (nodeaddr), Byte 2 (RW+addr), Bytes 3-6 (data), Byte 7 (CRC)
  • Read Request: Byte 0 (sync+rsv), Byte 1 (nodeaddr), Byte 2 (RW+addr), Byte 3 (CRC)
  • Read Reply: Byte 0 (sync+rsv), Byte 1 (0xFF), Byte 2 (addr=0), Bytes 3-6 (data), Byte 7 (CRC)

Sync nibble: 0x05 (Bits 0-3 = 1,0,1,0 transmitted LSB first)

Member Function Documentation

◆ CalculateCrc()

void tmc51x0::UartFrame::CalculateCrc ( )
inlinenoexcept

Calculate and set CRC8 checksum for the frame CRC8 is calculated over all bytes except the CRC byte itself.

Here is the call graph for this function:

◆ GetAddress()

uint8_t tmc51x0::UartFrame::GetAddress ( ) const
inlinenoexcept

Get register address from frame.

Returns
Register address (0x00-0x73) or 0xFF if invalid

◆ GetFrame()

void tmc51x0::UartFrame::GetFrame ( uint8_t * bytes) const
inlinenoexcept

Get the frame as raw bytes.

Parameters
bytesOutput buffer (must be at least GetSize() bytes)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSize()

size_t tmc51x0::UartFrame::GetSize ( ) const
inlinenoexcept

Get frame size in bytes based on type.

Returns
Frame size: 8 bytes for Write/Reply, 4 bytes for ReadRequest
Here is the caller graph for this function:

◆ GetValue()

uint32_t tmc51x0::UartFrame::GetValue ( ) const
inlinenoexcept

Get 32-bit data value from frame.

Returns
32-bit value (MSB-first) or 0 if ReadRequest
Here is the caller graph for this function:

◆ IsValid()

bool tmc51x0::UartFrame::IsValid ( ) const
inlinenoexcept

Check if frame is valid.

Returns
true if valid
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsWrite()

bool tmc51x0::UartFrame::IsWrite ( ) const
inlinenoexcept

Check if this is a write frame.

Returns
true if write frame

◆ ReadReply()

static UartFrame tmc51x0::UartFrame::ReadReply ( const uint8_t * bytes)
inlinestaticnoexcept

Construct a read reply frame from received bytes (8 bytes)

Parameters
bytesPointer to received frame bytes
Returns
UartFrame parsed from bytes
Here is the caller graph for this function:

◆ ReadRequest()

static UartFrame tmc51x0::UartFrame::ReadRequest ( uint8_t node_addr,
uint8_t reg_addr )
inlinestaticnoexcept

Construct a read request frame (4 bytes)

Parameters
node_addr8-bit node address (0-127)
reg_addrRegister address to read (0x00-0x73)
Returns
UartFrame with CRC8 automatically calculated
Here is the caller graph for this function:

◆ SetFrame()

void tmc51x0::UartFrame::SetFrame ( const uint8_t * bytes,
UartFrameType frame_type )
inlinenoexcept

Set the frame from raw bytes.

Parameters
bytesPointer to frame bytes
frame_typeType of frame (determines size)
Here is the call graph for this function:

◆ VerifyCrc()

bool tmc51x0::UartFrame::VerifyCrc ( ) const
inlinenoexcept

Verify CRC8 checksum of the frame.

Returns
true if CRC is valid, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Write()

static UartFrame tmc51x0::UartFrame::Write ( uint8_t node_addr,
uint8_t reg_addr,
uint32_t value )
inlinestaticnoexcept

Construct a write access frame (8 bytes)

Parameters
node_addr8-bit node address (0-127)
reg_addrRegister address to write (0x00-0x73)
value32-bit value to write
Returns
UartFrame with CRC8 automatically calculated
Here is the caller graph for this function:

Member Data Documentation

◆ frame

union tmc51x0::UartFrame::Frame tmc51x0::UartFrame::frame

◆ type

UartFrameType tmc51x0::UartFrame::type

Frame type.


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