Main Content

CAN FD Receive

R2026b

Receive CAN FD messages from a CAN interface

Since R2026b

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

Libraries:
Raspberry Pi Blockset / Communication

Description

The CAN FD Receive block receives messages from a Controller Area Network Flexible Data Rate (CAN FD) interface and outputs the received data for processing in a Simulink® model. Use this block to read CAN FD frames from a configured CAN interface on Raspberry Pi® hardware. The block supports both raw CAN FD output and structured message output enabling workflows for direct data processing or message-based applications.

The block supports two output workflows:

  • In the Raw data mode, the block outputs received message bytes as a uint8 vector.

  • In the CAN Msg mode, the block outputs a Simulink bus signal representing a CAN FD message. To extract individual fields from this message, use the CAN FD Unpack (Embedded Coder) block.

The block supports CAN FD message sizes up to 64 bytes and enables reception of CAN FD frames that use higher data rates during the data phase when bit rate switching is enabled.

Note

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

  • The CAN FD Receive block also supports reception of classical CAN messages when the CAN interface is configured for CAN FD. To receive 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

Receive CAN FD message data.

Use this workflow to directly process received CAN FD message data bytes without using structured CAN FD message. This approach is suitable for applications that operate on byte-level data or require minimal overhead.

In the CAN FD Receive block, set Data to be output as to Raw data to enable direct CAN FD data reception using a byte vector.

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

Configure additional message parameters such as:

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

During simulation, the block extracts data bytes from received CAN FD frames and outputs them as a uint8 vector. Each element in the output corresponds to one byte of the received message.

Receive CAN FD messages using a message-based workflow.

Use this workflow to receive CAN FD frames as structured message signals. This approach is suitable when you need access to message fields such as identifier, message, and CAN FD-specific signals. In this mode, the CAN FD Receive block outputs a Simulink bus signal that represents a complete CAN FD message. The message structure can be processed using a CAN FD Unpack (Embedded Coder) block which provides a consistent interface for extracting frame attributes.

Add a CAN FD Receive block to your Simulink model.

Set Data to be output as to CAN Msg to enable the block to output structured message data.

Connect the output of the CAN FD Receive block to the input port of the CAN FD Unpack (Embedded Coder) block.

Simulink model with a CAN FD Receive block that outputs CAN FD messages to a CAN FD Unpack block. This processes the message and provides individual fields such as data, identifier, and status.

Configure these message fields in the CAN FD Receive block:

Run the model to receive CAN FD messages.

During simulation, the CAN FD Receive block constructs a CAN FD message from the received data and outputs it as a structured bus signal. All message fields, including identifier, message, and protocol-specific flags, are derived directly from the received frame. The block preserves these values and outputs the message without modification.

Receive only specific CAN FD messages based on identifier and message size.

Use this workflow to filter incoming CAN FD traffic and process only relevant messages. This approach is useful when multiple nodes transmit data on the same CAN bus.

In the CAN FD Receive block, set Identifier type to match the incoming message format.

Specify Message ID to filter the desired CAN FD frame.

Set Message length to match the expected message size.

Run the model to receive filtered CAN FD messages.

During simulation, the block selects and outputs only those CAN FD frames that match the specified identifier and message length. Messages that do not meet the filter criteria are ignored.

Monitor receive status and detect communication issues.

Use this workflow to track message reception and identify error conditions during CAN FD communication.

In the CAN FD Receive block, select Output error.

Monitor the Error output port.

Run the model to receive CAN FD messages.

During simulation, the block outputs an error value indicating any communication errors during message reception.

Extended Examples

Ports

Output

expand all

Output data specified as either raw data or a structured CAN FD message.

  • When the Data to be output as parameter is set to Raw data, the output is a one dimensional uint8 vector containing the received data bytes.

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

Dependencies

Data Types: uint8 | bus

The port indicates the execution status of the CAN FD receive operation.

  • 0 — Indicates no CAN FD message is available during the current execution step.

  • 1 — Indicates CAN FD message is successfully received and made available at the output port of the block.

  • 2 — Indicates an error occurred during the CAN FD operation.

Data Types: uint8

Indicates error conditions during CAN FD message reception. The block outputs this signal when the CAN interface detects an error while receiving a message.

Error codes are listed in this table.

0000000000RXWARRXEPRXOVR
bit7bit6bit5bit4bit3bit2bit1bit0

RXOVR: Receive Buffer Overflow Flag bit

RXEP: Receive Error-Passive Flag bit

RXWAR: Receive 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 format of the received CAN FD data

  • Raw data — Accepts a uint8 vector.

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

Specify the identifier format used in the CAN FD frame.

Dependencies

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.

Dependencies

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

Dependencies

Specify the sample time of the block. When you specify this parameter as -1, Simulink determines the best sample time for the block based on the block context within the model.

Select this option to enable Error port indicating the error conditions during CAN FD message reception.

Dependencies

  • To enable this parameter, set Data to be output as to Raw data. To output the error in the CAN Msg form of output, select Output error of the CAN Unpack (Embedded Coder) block.

Extended Capabilities

expand all

Version History

Introduced in R2026b