Main Content

CAN FD Transmit

R2026b

Transmit CAN FD messages over a CAN interface

Since R2026b

  • Icon of the CAN FD Transmit block in the Raspberry Pi Blockset > Communication library.

Libraries:
Raspberry Pi Blockset / Communication

Description

The CAN FD Transmit block transmits messages over a Controller Area Network Flexible Data Rate (CAN FD) interface from a Simulink® model. Use this block to send CAN FD frames from Raspberry Pi® hardware through a configured CAN interface. CAN FD extends classical CAN by enabling larger CAN FD message sizes and higher data rates allowing efficient transmission of high-volume data.

The block supports two input workflows:

  • Raw CAN FD message transmission using a uint8 vector.

  • Message-based transmission using a structured CAN FD message. Use the CAN FD Pack (Embedded Coder) block to define the message fields.

The block supports CAN FD message sizes up to 64 bytes and allows transmission at higher data rates during the data phase using bit rate switching.

Note

  • To generate C/C++ code for this block, you must have an Embedded Coder® license.

  • The CAN FD Transmit block can also transmit classical CAN messages when the interface is configured for CAN FD. To transmit classical CAN messages, do not use bit rate switching and make sure the message size is 8 bytes or less.

For more information on how to enable the SPI interface and configure the MCP2518FD CAN FD controller for CAN FD configuration, see Enable and Configure Raspberry Pi for SPI and CAN FD Communication Using Waveshare 2-CH CAN FD HAT.

Examples

expand all

Transmit a CAN FD message.

Use this workflow to directly send byte-level data without constructing a structured CAN FD message. In this mode, the block transmits the input vector as the data field of a CAN FD frame.

In the CAN FD Transmit block, set Data is input as to Raw data to enable direct CAN FD message transmission using a byte vector.

Specify Message length based on the number of bytes to transmit. Use a value to match one of the supported CAN FD message sizes.

Provide a uint8 vector input whose length matches the specified message length. Each element of the vector represents one byte in the CAN FD message.

(Optional) Configure additional message parameters such as:

Run the model to transmit the CAN FD frame over the configured CAN interface.

During simulation, the block packages the input vector into a CAN FD frame using the specified message parameters and transmits it over the selected interface. If bit rate switching is enabled, the message is transmitted at a higher data rate during the data phase.

Transmit a CAN FD message using a message-based workflow.

Use this workflow to construct and transmit CAN FD frames using a structured message format which enables explicit configuration of message fields such as identifier, message length, and CAN FD-specific flags. In this mode, the CAN FD Transmit block accepts a Simulink bus signal that represents a complete CAN FD message. The message structure is typically created using a CAN FD Pack (Embedded Coder) block which provides a consistent interface for specifying frame attributes.

Add a CAN FD Pack (Embedded Coder) block to your Simulink model.

Connect the output of the CAN FD Pack (Embedded Coder) block to the input port of the CAN FD Transmit block.

In the CAN FD Transmit block, set Data is input as to CAN Msg to enable the block to accept structured message input.

Simulink model with a counter connected to CAN FD Pack block which feeds into a CAN FD Transmit block for sending CAN FD messages to Raspberry Pi.

Configure these message fields in the CAN FD Transmit block:

Run the model to transmit CAN FD messages.

During simulation, the CAN FD Transmit block forwards the structured CAN FD message to the configured CAN interface. All frame properties, including identifier, message, and flags, are derived directly from the input bus. The block preserves these values and transmits the message without any modification.

Transmit CAN FD messages at higher data rates.

Use this workflow to increase the effective data throughput of CAN FD communication. CAN FD supports transmitting the data phase of a frame at a higher bit rate than the arbitration phase using bit rate switching.

In the CAN FD Transmit block, select Enable bit rate switching to transmit CAN FD frames using an increased data rate during the data phase.

Configure the CAN interface with appropriate nominal and data bit rates.

Run the model to transmit the CAN FD message.

During transmission, the block sends CAN FD frames using the nominal bit rate for arbitration. When bit rate switching is enabled, the block transmits the data at a higher bit rate during the data phase, resulting in improved communication efficiency.

Extended Examples

Ports

Input

expand all

Input data specified as either raw data or a CAN FD message structure.

  • When the Data is input as parameter is set to Raw data, the input is a one dimensional uint8 vector.

  • When the Data is input as parameter is set to CAN Msg, the input is a Simulink bus signal representing a CAN FD message.

Dependencies

Data Types: uint8 | bus

Output

expand all

The port indicates the execution status of the CAN FD transmit operation. The port outputs 1 for successful transmit and these error codes in case of any failure.

0000ABTFMLOATXERRTXBOTXEPTXWAR
bit7bit6bit5bit4bit3bit2bit1bit0

ABTF: Message Aborted Flag bit

MLOA: Message Lost Arbitration bit

TXERR: Transmission Error Detected bit

TXBO: Bus-Off Error Flag bit

TXEP: Transmit Error-Passive Flag bit

TXWAR: Transmit Error Warning Flag bit

Dependencies

Data Types: uint8

Parameters

expand all

Specify the CAN interface used to receive CAN FD messages. To find the name of the CAN interface, in the Raspberry Pi terminal, execute the ip link show type can command. To configure the CAN interface, see CAN.

Specify the data input type used for transmitting messages.

  • Raw data — Accepts a uint8 vector.

  • CAN Msg — Accepts a CAN FD message bus signal.

Enable bit rate switching to transmit data at a higher rate during the data phase of the CAN FD frame. During arbitration, nominal bit rate is used. When enabled, the data phase transmits faster thus, increasing throughput.

When selected, the block waits for the time specified in the Time in seconds parameter before transferring data.

  • on — When you select this parameter, the block operates in the Blocking mode. If the message received in the previous time step is sent, the block accepts message from the input port. If the send operation is in progress, the block waits for the time specified in the Time in seconds parameter, and then it accepts message from the input port.

    A task overrun occurs if the target hardware is still waiting for the requested message to be sent when the next send operation is scheduled to begin. To fix overruns:

    • Increase the sample time of input message.

    • Reduce the length of message at the input port.

  • off — When you clear this parameter, the block operates in the Non-blocking mode. If the transmission of the message received in the previous time step is still in progress, the message at the input port at the given time step is dropped.

Specify the wait time for sending the message. After the specified time, the block times out.

Dependencies

Select this option to enable Status port that indicates the status of message transfer. The status port outputs 0 for successful transmit and error codes in case of failure. For more information on error codes for transmit operation, see Status.

Specify the identifier format used in the CAN FD frame.

Specify the message identifier of the CAN FD frame. The specified identifier is encoded in the CAN FD message that the block transmits on the CAN bus.

The valid identifier range depends on the selected identifier type. This identifier is 11 bits long for standard frames and 29 bits long for extended frames. You can specify the identifier in decimal form. To use binary or hexadecimal values, convert the value using bin2dec('') or hex2dec(''), respectively.

Specify the number of data bytes in the CAN FD frame with supported message sizes up to 64 bytes.

Extended Capabilities

expand all

Version History

Introduced in R2026b