Main Content

FDCAN Write

Write data to the FDCAN Bus

Since R2023a

Add-On Required: This feature requires the Embedded Coder Support Package for STMicroelectronics STM32 Processors add-on.

  • FDCAN Write block

Libraries:
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32G4xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32H7xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32L5xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32U5xx Based Boards

Description

The FDCAN Write block writes messages to the Controller Area Network (CAN) network connected to the hardware.

The FDCAN Write block accepts a CAN data that needs to be sent when operation mode is set to Data. The block accepts a 1-D array of type uint8 when data format is set to Raw data.

The block accepts input as Simulink® bus signal when data format is set to CAN Message. To extract data from Simulink bus signal, connect it to FDCAN pack block.

Select the Operation mode and its properties using the block parameters dialog box. Configure the properties of FDCAN module in the configuration parameters.

Examples

Ports

Input

expand all

The block accepts messages in Raw data format. To accept the message as a uint8 vector array, set Data Format to Raw data.

Dependencies

To enable this port, set the Data format to Raw data.

Data Types: uint8

The block accepts messages in CAN Message format.

You can create your messages or you can upload a CAN database file to FDCAN Pack block.

Dependencies

To enable this port, set the Data format to CAN Message.

Data Types: CAN Message

The port accepts the length of the received CAN message in bytes.

Dependencies

To enable this parameter, set Data format to Raw data and Data length via to Inport.

Data Types: uint8

The port accepts FDCAN message identifier. The ID can be:

  • 0-2047: for Standard (11-bit identifier)

  • 0-536870911: for Extended (29-bit identifier)

Dependencies

To enable this parameter, set Data format to Raw data and Identifier via to Inport.

Data Types: uint32

The port accepts CAN message identifier type

  • 0 - if its 11-bit standard identifier

  • 1 or any value other than 0 - if its 29-bit standard identifier

Dependencies

To enable this parameter, set Data format to Raw data and Identifier type via to Inport.

Data Types: uint8

The port accepts a logical value to put the FDCAN peripheral in sleep mode.

Dependencies

To enable this port, set Operation mode to sleep.

Data Types: uint8

The port accepts a logical value to put the FDCAN peripheral in wakeup mode.

Dependencies

To enable this port, set Operation mode to wakeup.

Data Types: uint8

The port accepts a logical value to put the FDCAN peripheral in restricted mode.

Dependencies

To enable this port, set Operation mode to Exit restricted operation mode.

Data Types: uint8

Output

expand all

The port outputs message read status.

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

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

Dependencies

To enable this port, select Output Status parameter.

Data Types: uint8

The port outputs the received FIFO fill level.

Dependencies

To enable this parameter, select Output transmit FIFO level parameter.

Parameters

expand all

Module to which the FDCAN device is connected.

Select the FDCAN read operation mode.

  • Data - Data to write FDCAN data/message

  • Sleep - Select to set the FDCAN module in sleep mode. In Sleep operation mode, the block accepts a logical value to put the FDCAN peripheral in sleep mode. When you set operation mode to sleep, it enables the input port Sleep.

  • Wakeup - Select to wakeup the FDCAN module from sleep mode. In Wakeup operation mode, the block accepts a logical value to gets the FDCAN peripheral in wakeup state. When you set operation mode to wakeup, it enables the input port Wakeup.

  • Exit restricted operation mode - Select to exit the FDCAN module from restricted mode. In Exit restricted operation mode, the block accepts a logical value to exit the FDCAN peripheral from restricted operation mode. When you set operation mode to exit restricted operation mode, it enables the input port Restricted Mode.

Select an output type to write message.

  • RAW data – To write message as a 8-by-1 uint8 array, select Data format as Raw data.

  • CAN Message – To write message in CAN Message format, select Data format as CAN Message.

Select an output type to write message.

  • RAW data – To write message as a 8-by-1 uint8 array, select Data format as Raw data.

  • CAN Message – To write message in CAN Message format, select Data format as CAN Message.

Select the Identifier Type via Dialog or input port.

  • When you select Identifier Type via inport, the block configures an input port, Id Type.

  • When you select Identifier Type via Dialog, the block accepts CAN message.

Dependencies

To enable this parameter, set the Data format as Raw data.

The type of message identifier.

Dependencies

To enable this parameter, set the Identifier type via as Dialog.

The type of message identifier.

  • 0-2047: for Standard (11-bit identifier)

  • 0-536870911: for Extended (29-bit identifier)

Dependencies

To enable this parameter, set the Data format as Raw data.

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 identifier is coded into a message that is sent to the CAN bus.

Dependencies

To enable this parameter, set the Data Format as Raw data. To output the identifier of the CAN Msg, select Output identifier of the CAN Unpack block.

Select the Data length via Inport or Dialog.

  • When you select Data length via inport, the block configures an input port, Length.

  • When you select Data length via Dialog, the block accepts specified input data size.

Dependencies

To enable this parameter, set the Data format as Raw data.

The length of the message, in bytes provided via input.

Dependencies

To enable this parameter, set the Data length via as Dialog.

Select this parameter to enable bitrate switching.

Dependencies

To enable this parameter, set the Data Format as Raw data, Operation mode as Data and Frame format as CAN-FD.

The block sends a remote frame in the CAN message if this parameter is selected. The data at the input port is not sent in the CAN message.

Dependencies

To enable this parameter, set the Data Format as Raw data and Frame format as CAN. For CAN Msg, the Remote Frame is inherited from the request specified in the CAN Pack block.

When you select the Output receive FIFO fill level parameter, the block configures an output port, FIFO level. The port outputs the received FIFO message level.

When you select the Output Status parameter, the block configures an output port, Status. The port outputs the status message.

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.

Specify the time in seconds to block the CAN read. For nonblocking, set to 0. You configure Timeout to be the maximum time (in seconds) to wait to complete a read operation.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2023a