Contenuto principale

Configure CAN Interfaces and Apply Message Filtering

When configuring a CAN interface, in addition to the basic steps, you can define how each CAN interface operates and manage the flow of messages on the bus. These additional steps include selecting the number and type of interfaces, setting bus speed and buffer size, and applying message filters. Filtering restricts processing to messages that match specified identifiers, which is useful when the network carries data from multiple devices.

Configuration of CAN Interfaces

Complete these steps to configure the CAN interfaces.

  1. Open the model containing a CAN block and navigate to in the ROS tab of the Simulink® toolstrip.

  2. In the Prepare section, select Hardware Settings to open the Hardware Implementation section of the model configuration parameters.

  3. Under Hardware board settings, select Target hardware resources > CAN > Configure CAN Interface to configure the parameters listed in the table.

    Note

    If you select Target hardware resources, you must have sudo access on the target hardware to create CAN interfaces and execute the deployed Simulink model.

    ParametersDescription
    Number of InterfacesSelect up to five SocketCAN interfaces that are available in the CAN network. This enables you to configure the to configure the CAN interface type, bus speed, and transmit queue buffer size for each of the CAN interfaces.
    CAN InterfaceSpecify this parameter to the CAN device ID to identify and manage the particular CAN interface on the network.
    CAN Interface TypeSet this parameter to Real to create a physical CAN channel on the CAN bus and Virtual to create a virtual CAN channel on the CAN bus. The default value of this parameter is Real.
    Bus Speed (kbps)Set this parameter to a value ranging between 5 to 1000 kbps. This value refers to the data transmission rate on the CAN network. The default value of this parameter is 500 kbps.
    Transmit Queue Buffer SizeSet this parameter to enter the transmit buffer queue size for the CAN interface. This number refers to the maximum amount of data you can queue for transmission and send to the CAN bus. The default value of this parameter is 65536.

Enabling Message Filtering

You can enable filtering when the CAN bus carries data from many devices but you want to log, monitor, or act on only a subset of messages. You can use these filters so that the block accepts only frames that match a chosen identifier or range and ignores the rest. Filtering prevents unnecessary traffic from reaching your model and keeps downstream processing focused on the most relevant data.

You can set filters for the ROS Msg and CAN Msg message types. You can set these filters by configuring the ID Type, Acceptance Mask, and Acceptance Filter parameters for up to four messages.

ID TypeUse this parameter to set the message identifier to Normal or Extended. The default value of the parameter is Normal.
Acceptance MaskUse this parameter to specify the receive mask, which controls at the bit level whether each identifier bit is compared for filtering or ignored.
Acceptance FilterUse this parameter to specify the identifier value against which to compare incoming CAN messages. If the active filter bits match, the block accepts the message and places it in the receive buffer. Otherwise, it discards the message.

To ignore all filters and enable transmission of all messages, select the Allow All Messages parameter.

See Also

|

Topics