Main Content

CAN Receive

Receive messages from the controller area network (CAN) bus

  • Library:
  • NVIDIA Jetson and NVIDIA DRIVE / Communication

  • NVIDIA CAN receive block

Description

The CAN Receive block receives messages from the CAN bus through the time triggered CAN (TTCAN) controller available on NVIDIA® embedded boards. This block uses the SocketCAN interface to communicate with the CAN controller hardware on NVIDIA boards.

You can also use this block to interact with a virtual CAN interface. A virtual CAN interface allows transmission and reception of CAN frames without a native CAN interface associated with real hardware. For more information on how to set up a virtual CAN interface, see Setup Virtual CAN Interface.

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

Ports

Output

expand all

Received message data, returned as a vector or scalar.

If Data to be output as is set to Raw data, the received message data is an 1-by-N array of type uint8.

If Data to be output as is set to CAN Msg, the data port is renamed to CAN Msg and the received message data is output as a Simulink® bus signal. To extract data from Simulink bus signal, use the CAN Unpack block from Vehicle Network Toolbox.

Data Types: uint8 | CAN Msg

Status of the received output message.

Data Types: uint8

Error codes.

Dependencies

To enable this parameter, select Output Error.

00000000RXWARRXEPRX0OVRRX1OVR
bit7bit6bit5bit4bit3bit2bit1bit0

RX1OVR: Receive Buffer 1 Overflow Flag bit

RX0OVR: Receive Buffer 0 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

Specify the name of the real or virtual CAN interface to use.

Programmatic Use

Block Parameter: DeviceID
Type: character vector
Values: valid device name
Default: 'can0'

Select this parameter to bring up the CAN interface on the NVIDIA target before receiving CAN frames.

Programmatic Use

Block Parameter: SetupCAN
Type: character vector
Values:'off'|'on'
Default: 'off'

Select the type of CAN interface.

  • If the CAN interface type is Real, set this parameter to Real. Setting this parameter to Real would not bring up the CAN interface in these scenarios.

    • The interface is already brought up on the target with a CAN-Bus Speed that does not match with the CAN Bus Speed (kBit/s) parameter. The block would not transmit the CAN frames. Bring the existing interface down before enabling this parameter.

    • If the interface is already brought up on the target with the CAN-Bus Speed that matches with the CAN Bus Speed (kBit/s) parameter. The block will transmit the CAN frames.

  • If the CAN interface type is Virtual, set this parameter to Virtual.

Dependencies

To enable this parameter, select Set up CAN interface.

Programmatic Use

Block Parameter: TypeofCAN
Type: character vector
Values:'Real'|'Virtual'
Default: 'Real'

Data type used for receiving messages.

Programmatic Use

Block Parameter: OutputDataType
Type: character vector
Values: 'Raw data'|'CAN Msg'
Default: 'Raw data'

Message identifier type.

Dependencies

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

Programmatic Use

Block Parameter: IdentifierType
Type: character vector
Values: 'Standard (11-bit identifier)'|'Extended (29-bit identifier)'
Default: 'Standard (11-bit identifier)'

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

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

Programmatic Use

Block Parameter: MessageId
Type: character vector
Values: '100'|scalar
Default: '100'

Message length.

Dependencies

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

Programmatic Use

Block Parameter: MsgLength
Type: character vector
Values: '8'|scalar
Default: '8'

Specify how often the block should read the port buffer. Enter a value greater than 0 or -1 (for inherited sample time).

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

This value defaults to a sample time of 0.1 seconds. Smaller values require the processor to complete the same number of instructions in less time and this can cause task overruns.

Programmatic Use

Block Parameter: sampletime
Type: character vector
Values: scalar | vector
Default: '0.1'

Select to output error codes if the message transfer fails.

Programmatic Use

Block Parameter: OutputError
Type: character vector
Values:'off'|'on'
Default: 'off'

Select to output remote messages.

Programmatic Use

Block Parameter: OutputRemote
Type: character vector
Values:'off'|'on'
Default: 'off'

Tips

  • If a Simulink model contains CAN Transmit and CAN Receive block, and the Set up CAN interface is set only on the CAN Transmit block, then a CAN receive socket might not be set up because of the order of execution of the blocks. In such cases, manually set up the CAN interfaces before executing the models or enable Set up CAN interface on all blocks.

Version History

Introduced in R2021b