Main Content

On-board CAN Receive

Receive messages using on-board Arduino CAN controller

Since R2024b

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

  • Arduino On-board CAN Receive block icon

Libraries:
Simulink Support Package for Arduino Hardware / Communication

Description

Use the On-board CAN Receive block to receive CAN messages from the on-board Arduino® CAN controller. The block stores input messages in mailboxes in a first-in, first-out (FIFO) method. These mailboxes deliver the CAN messages to your Simulink® model in a queued order at every sample time.

Supported Arduino Boards

  • Arduino Due

  • Arduino compatible Teensy 4.0 and 4.1

Ports

Output

expand all

The block outputs CAN data read from the on-board Arduino CAN controller. To output the CAN data as a uint8 message vector, set Data to be output as to Raw data. To output the data in CAN message format, set Data to be output as to CAN Msg.

Dependencies

Data Types: uint8 | CAN Msg

The block outputs CAN message read status.

  • The status is 1, if the block reads new CAN message.

  • The status is 0, if the block reads no new CAN message.

Dependencies

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

Data Types: uint8

The block outputs the CAN message error status.

  • The status is 1, if the input CAN message contains an error.

  • The status is 0, if the input CAN message to the block has no error.

Dependencies

Data Types: uint8

The block outputs the remote message frame status.

  • The status is 1, if the incoming CAN data is a remote frame.

  • The status is 0, if the incoming CAN data is not a remote frame.

Dependencies

  • To enable this port, set Data to be output as to Raw data and select Output remote.

Data Types: uint8

The block outputs CAN messages at a particular timestamp as a signal bus or arduinoCANMsg.

Dependencies

  • To enable this port, set Data to be output as to CAN Msg.

Data Types: uint8 | bus

Parameters

expand all

Select the CAN controller according to the Arduino board you use.

Arduino BoardsSupported CAN Controller
Arduino DueCAN0 and CAN1
Arduino compatible Teensy 4.0 and 4.1CAN1, CAN2, and CAN3

For more information on how to assign or view the Arduino board pins for the On-board CAN Receive block, click View pin map.

Select an output message type.

  • Raw data — Select this option to read message as a 1-by-N uint8 array.

  • CAN Msg — Select this option to read message in CAN message format.

    Perform these steps to read message in CAN message format.

    • To your Simulink model, add a CAN Unpack (Vehicle Network Toolbox) from the Vehicle Network Toolbox™.

    • Connect the output of the On-board CAN Receive block to the input of the CAN Unpack (Vehicle Network Toolbox) block.

    • 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 inherits the message properties from the uploaded file.

On-board CAN Receive and CAN Unpack blocks connections

Specify the CAN identifier type.

  • Standard (11-bit identifier) — Use this option to create CAN messages with a standard 11-bit identifier.

  • Extended (29-bit identifier) — Use this option to create CAN messages with an extended 29-bit identifier.

Dependencies

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

Specify the message identifier, which is 11 bits long for the standard CAN frame size or 29 bit long for the extended CAN frame size. You can specify the value in decimal, binary, or hexadecimal. For binary and hexadecimal formats, use bin2dec and hex2dec, respectively. The message identifier is coded into a message that is sent to the CAN bus.

Dependencies

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

Specify the length of CAN message in bytes.

Dependencies

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

Specify how often the block reads CAN messages from the on-board Arduino CAN controller, in seconds.

Message

To enable the parameters under the Message section, set Data to be output as to Raw data.

Select this option to request error status of the CAN message. To output the error in the CAN Msg message type, select Output error in the CAN Unpack (Vehicle Network Toolbox) block.

Select this option to request data from a CAN node. This option enables the Remote output port

Version History

Introduced in R2024b