Main Content

Polling-Based CAN Communication Using MCAN Blocks of Infineon AURIX TC4x

This example shows how to use the MCAN Transmit and MCAN Receive blocks from Embedded Coder® Support Package for Infineon® AURIX™ TC4x Microcontrollers to handle polling-based communication between different CAN modules of Infineon® AURIX™ TC4x Microcontrollers.

Introduction

Controller area network (CAN) is widely employed communication protocol in automotive and industrial settings that facilitates real-time data exchange among electronic control units (ECUs). Serving as a multi-controller serial bus standard connecting a minimum of two nodes, CAN operates on a message-based protocol initially intended for in-vehicle communication. Its key advantages include a notable reduction in wiring complexity and the effective prevention of message collisions. CAN with flexible data-rate (CAN FD) is an extension of the classic CAN protocol that improves real-time performance. It allows data rates higher than 1 Mbps and payloads longer than 8 bytes and up to 64 data bytes.

This example implements polling based transmission and reception of CAN messages using MCAN blocks. The LEDs on the hardware board blink in the pattern that matches the binary value of the transmitted messages. Infineon AURIX TC4x microcontrollers have an onboard transceiver, TLE9351VSJ, which you can use for CAN communication.

Prerequisites

Complete the Getting Started with Embedded Coder Support Package for Infineon AURIX TC4x Microcontrollers example.

Required Hardware

  • Infineon AURIX TC4x - TriBoards

  • Micro-USB cable

Available Model

Open the tc4xMcanWithPolling model.

The free-running counter sends 0-15 values to the MCAN Transmit block at a 1-second interval. You can change the connection to 3-bit counter to transmit values from 0 to 7.

The MCAN Transmit block uses the Module 0 Node 0 configuration to transmit the counter data in raw data format with a data length of 1 byte and the standard identifier set to 1200. The MCAN receive block uses the Module 1 Node 0 configuration to receive data in a buffer register with the identifier set to 1200 in the first standard filter. You can analyze the configured parameters in MCAN Transmit, MCAN Receive blocks, and Hardware Mapping tool.

The CAN FD Unpack block unpacks the received message data and the model converts the received value to binary values. These binary values are used to blink the LEDs at the P33.0, P33.1, P33.4 and P33.5 pins on the hardware board. The pattern in which the LEDs blink corresponds to binary numbers from 0 to 15 that change at a 1-second interval.

The tc4xMcanWithPolling/Initialize subsystem in the model enables the onboard CAN transceiver, TLE9351VSJ.

Configure the Model

1. Open the tc4xMcanWithPolling model.

2. Double-click the MCAN Transmit block and confirm that the Data format is set to Raw data, Identifier to 1200, and Data length to 1 byte.

3. The MCAN Receive block uses buffers to receive data in the packed form. Analyze Read source and Output type parameters by double-clicking the MCAN Receive block.

4. The CAN FD Unpack block unpacks the received message. Double-click the CAN FD Unpack block to ensure that the Identifier and Length (bytes) parameter values match with those in the MCAN Transmit block.

5. Press Ctrl+E to open the Configuration Parameters dialog box. Click the Hardware Implementation pane and set Hardware board to Infineon AURIX™ TC4x - TriBoards.

6. On the Hardware tab, click Hardware Mapping to open the mapping browser associated with the model.

7. The model transmits data from Module 0 to Module 1 of Node 0. Observe that the the Node 1 parameter of the MCAN Transmit peripheral set to Module 0 Node 0, and the Node 1 parameter of the MCAN Receive peripheral set to Module 1 Node 0.

8. Click MCAN on the left pane, navigate to Module 1 Node 0 > Standard filter, and verify the values of the Configuration and Id1 parameters. The values must match the values in the MCAN Receive and CAN FD Unpack blocks.

Generate Code and Deploy Model to Target Hardware

Complete the following steps to generate code and run the model on the target hardware.

1. Open the tc4xMcanWithPolling model.

2. Click Build, Deploy & Start on the Hardware tab to deploy the target model to the hardware.

3. Follow the build process by opening the diagnostic viewer using the link provided at the bottom of the model canvas. You can observe that the code generation report contains code for model traceability. Infineon AURIX deploys the model to the hardware using a downloading tool.

4. Observe the blinking LEDs at the P33.0, P33.1, P33.4, and P33.5 pins on the hardware board. The pattern in which the LEDs blink corresponds from 0 to 15 that change at a 1-second interval.

Run Model in Monitor and Tune Mode

1. Open the tc4xMcanWithPolling model.

2. Select a COM Port. To see a list of available COM ports on your computer, select Start > Control Panel > Device Manager > Ports (COM &LPT).

3. In your Simulink model, press Ctrl+E or click Modeling > Model Settings to open the Configuration Parameters dialog box. Navigate to Hardware Implementation > Target hardware resources > Connectivity. Set the Connectivity interface to Serial(ASCLIN0) for the external mode.

4. On the Hardware tab, click Monitor & Tune to configure the model for simulation. At this point, your model runs on the Infineon AURIX TC4x hardware board and communicates with Simulink so that you can monitor and tune the parameters.

5. Observe the blinking LEDs that correspond to binary numbers from 0 to 15. You can also send the data from 3-bit counter and observe three blinking LEDs corresponding to binary numbers from 0 to 7.