Main Content

CAN Receive

Receive message from CAN network

Add-On Required: This feature requires the Simulink Support Package for Raspberry Pi Hardware add-on.

  • CAN Receive block

Libraries:
Simulink Support Package for Raspberry Pi Hardware / Communication

Description

The CAN Receive block receives messages from the CAN network. This block uses SocketCAN which is a device-independent driver for implementing the CAN interface supporting all CAN shields.

The CAN Receive block supports Raw data and CAN Msg as output types. To use a CANdb (CAN database) file or to specify signals manually, use CAN Msg output type and the CAN Unpack block. The CAN Unpack block is available from Vehicle Network Toolbox™. For more information on the CAN Unpack block, see CAN Unpack (Vehicle Network Toolbox).

For more information on how to enable the SPI interface and configure the MCP2515 CAN controller for CAN communication, see Enable and Configure Raspberry Pi for SPI and CAN Communication Using MCP2515 CAN Controller.

You can use CAN Receive block to interact with a real or virtual CAN interface. To bring up the CAN interface with Raspberry Pi®, refer to the user guide of your CAN shield. For more information on how to set up a virtual CAN interface, see Setup Virtual CAN Interface.

Ports

Output

expand all

Received message data, returned as a vector or scalar.

Data Types: uint8 | CAN Msg

Status of the received output message.

Data Types: uint8

Error codes.

Dependencies

To enable this parameter, select Output Error.

0000000000RXWARRXEPRXOVR
bit7bit6bit5bit4bit3bit2bit1bit0

RXOVR: Receive Buffer Overflow Flag bit

RXEP: Receive Error-Passive Flag bit

RXWAR: Receive Error Warning Flag bit

Remote message flag.

Dependencies

To enable this parameter, select Output Remote.

Parameters

expand all

Enter the name of the real or virtual CAN interface. To find the name of the CAN interface, in the Raspberry Pi terminal, execute the ifconfig command. To configure the CAN interface, see CAN properties.

Select a type to receive message.

  • Raw data – To receive message as a 1-by-N uint8 array, select Data to be output as as Raw data.

  • CAN Msg – To receive message in CAN message format, select Data to be output as as CAN Msg and then perform these steps:

    1. Add a CAN Unpack (Vehicle Network Toolbox) block to your Simulink® model.

    2. Connect the output of the CAN Receive block to the input of the CAN Unpack (Vehicle Network Toolbox) block.

    3. Using the options in the Data to be output as list of the CAN Unpack (Vehicle Network Toolbox) block, specify if you want to create your messages or you want to upload a CAN database file. If you choose to upload a CAN database file, the CAN Unpack (Vehicle Network Toolbox) inherits the message properties from the uploaded file.

    Note

    To use the CAN Unpack (Vehicle Network Toolbox) block, you must have a Vehicle Network Toolbox license.

The type of message identifier.

Dependencies

This parameter appears only when you select Data to be output as as Raw data.

Message identifier, which is 11 bits long for the standard frame size or 29 bits long for the extended frame size, specified in decimal, binary, or hex. For binary and hex formats, use bin2dec(' ') and hex2dec(' '), respectively, to convert the entry. The message identifier is coded into a message that is sent to the CAN bus.

Dependencies

This parameter appears only when you select Data to be output as as Raw data. To output the identifier of the CAN Msg, select Output identifier of the CAN Unpack block.

The length of the message, in bytes.

Dependencies

This parameter appears only when you select Data to be output as as Raw data. To output the length of the CAN Msg, select Output length of the CAN Unpack block.

Specify how often the block receives message, in seconds. When you specify this parameter as -1, Simulink determines the best sample time for the block based on the block context within the model.

When you select the Output Error parameter, the block configures an output port, Error. The port outputs the error code as a uint8 integer. Each bit in code corresponds to the type of error in the received message. An output of 0 indicates that the message is error-free. Any value other than 0 indicates that the message is an error frame.

Dependencies

This parameter appears only when you select Data to be output as as Raw data. To output the error in the CAN Msg, select Output error of the CAN Unpack block.

Select this parameter to enable the Remote output port. This port outputs the message remote frame status.

Dependencies

To enable this parameter, set Data to be output as to Raw data.

Version History

Introduced in R2019b