comm/packet.c and comm/packet.h.
Packet structure
Every packet is wrapped in a frame that provides length and integrity information.- Short packet (≤ 255 bytes)
- Long packet (256 – 512 bytes)
- The maximum payload length is 512 bytes (
PACKET_MAX_PL_LENinpacket.h). - The first byte of the payload is always the
COMM_PACKET_IDcommand byte. - The CRC is computed over the payload bytes only (not the start byte, length, or stop byte).
- The stop byte is
0x03for both short and long frames.
The start byte distinguishes frame types:
0x02 means a one-byte length field follows; 0x03 means a two-byte length field follows.Packet layer API
Thepacket.h API manages framing state for each communication channel:
Communicating from an external microcontroller
1
Connect UART
Connect your microcontroller’s TX to the VESC RX pin and RX to the VESC TX pin. Use the baud rate configured in VESC Tool under App Settings -> UART -> Baud Rate (default: 115200). Ensure common ground.
2
Build a packet
Construct a payload starting with the
COMM_PACKET_ID byte followed by any required data bytes for that command. Encode it into a frame (start byte, length, payload, CRC16, stop byte).3
Send and receive
Transmit the frame over UART. For commands that return data (e.g.,
COMM_GET_VALUES), wait for the VESC to send a response frame and decode it the same way.Minimal C example: set duty cycle
COMM_PACKET_ID command reference
The first byte of every payload is aCOMM_PACKET_ID value, defined in datatypes.h.
Motor control commands
Telemetry commands
Configuration commands
System commands
Firmware update commands
CAN forwarding
For the complete list of all 159+ commands, see
datatypes.h and the handler in comm/commands.c.
