Main Content

Communication with MCAN Blocks

This example shows how to use the MCAN blocks to set up MCAN communication between the target hardware and your host computer for Texas Instruments™ C2000™ Microcontroller Blockset.

Introduction

Using this example, you will learn how to establish a communication between target hardware and the host computer using MCAN Transmit and Receive blocks on the target hardware and Vehicle Network Toolbox™ (VNT) CAN Transmit and Receive blocks on the host.

Prerequisites

Complete the following tutorials:

Required Hardware:

  • Any Texas Instruments™ C2000™ board with MCAN module.

  • A CAN-FD hardware.

Note: If you are trying to run this example on a Launchpad, connect the TX and RX pin to the vector CAN device. Incase of Control card, a Transceiver (TCAN EVM transceiver) is required between vector CAN device and Control card.

CAN-FD Communication between Host Computer and Target Hardware

In this task, you will transmit counter data from the host to the target hardware in two parts.

  • When the target hardware receives a new message from host, it transmits that data with a different message ID back to the host.

  • The host then displays the transmitted and received CAN signals.

Target Model

1. Open the target c2000MCANTargetModel.slx model.

open_system('c2000MCANTargetModel.slx');

2. The example model is configured for the TI F28P650D launchpad. To select a different target hardware, in the Simulink® Editor, browse to Configuration Parameters > Hardware Implementation > Hardware board.

3. Navigate to Hardware Implementation > Target Hardware Resources > MCAN_A. For target hardware with only one MCAN module, navigate to Hardware Implementation > Target Hardware Resources > MCAN.

4. Set the protocol mode to CAN-FD and nominal baud rate to 500Kbps.

5. Enable Bit rate switching and set the data baud rate to 1Mbps.

6. Configure the Tx and Rx pins and standard filters. Configure standard filter 0 in the model to receive data into the RX buffer with a receive message standard filter ID of 768 (0x300). You can also view and validate the memory configuration.

7. Following are the MCAN block configurations done for target model. Double-click on the blocks to open block parameter configurations. Ensure the specified parameter values are the same if you want to run this example for other hardware board.

  • The RX buffer 0 receives the CAN message, and the MCAN Receive block outputs the packed CAN message.

  • The CAN FD Unpack block unpacks the received CAN message, outputting the raw CAN data. The protocol, identifier, and data length to be unpacked are configured in this block.

  • The MCAN Transmit block transmits the raw data. The protocol, identifier, and data length are configured on the block, along with the bit rate switching for the transmitted message.

8. Click Build, Deploy & Start in the Hardware tab or press Ctrl+B to build and download the executable file.

Run Host Model

1. Open the host c2000MCANHostModel.slx model.

open_system('c2000MCANHostModel.slx');

2. Configure the device for CAN-FD Configuration, CAN-FD Transmit, and CAN-FD Receive blocks.

  • Ensure that the Arbitration bus speed and the data bus speed set on the CAN FD configuration block match the nominal baud rate and the data baud rate on the target, respectively.

  • The standard filter identifier of the message transmitted from the host must match the identifier of the receive block in the target model. Similarly, the identifier of the message received at the host model should match the identifier of the transmit block in the target model.

Note:

  • The models in this example use the Vector VN1610 1 hardware. However, you can connect your models to other supported hardware.

  • Select the CAN device and channel as per your configuration.

  • CAN Configuration, CAN Transmit and CAN Receive blocks on the host are from the Vehicle Network Toolbox™ library.

3. Set the Stop time to Inf and click on Run.

4. Observe and compare the CAN data received from target hardware and transmitted from host.

More About