Main Content

Serial Communication Using SCI Blocks

This example shows how to use the SCI blocks to set up serial communication between the target hardware and your host computer for Embedded Coder® Support Package using the Texas Instruments™ C2000™ Processors.

Introduction

Using this example, you will:

  • Establish communication between the target hardware and the host computer using SCI Transmit and Receive blocks on the target hardware and Instrumentation Control Toolbox™ Serial Transmit and Receive blocks on the host.

  • Establish communication between the target hardware and the host computer using SCI Transmit and Receive blocks on the target hardware and a MATLAB® script on the host.

  • Use the polling and interrupt methods to receive data on the target hardware.

Prerequisites

Complete the following tutorials:

  • Set Up Serial Communication with Target Hardware. There are different control card versions available for C2000™ processors. In some control cards, the SCI_A module pins are directly connected to the USB docking station and other control cards have a MAX32xx chip for RS-232 communication on the control card.

Required Hardware

  • Any Texas Instruments C2000 board

Task 1 - Serial Communication between Host Computer and Target Hardware using Serial Transmit and Receive Blocks on Host

In this task, you transmit counter data from the host to the target hardware using Simulink® model on the host. When the target hardware receives data on polling, it transmits the same data back to the host. The host then displays the transmitted and received signals.

Target Model

1. Open the target model.

open_system('c28x_sci_comm.slx');

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

3. Navigate to Hardware Implementation > Target Hardware Resources > SCI_A and set the Baud rate to 115200.

4. The model is configured to receive the data without header and terminator at a sample time of 0.001 s and to transmit the same data.

5. Following figure shows the SCI block configurations for the 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 boards.

Things to consider

You must consider the following things when configuring the SCI Receive block. In this example, the c28x_sci_comm model is configured to Wait until data received with timeout for blocking mode.

  • Blocking mode - Select the Wait until data received parameter and set Timeout to inf. In this mode, if data is not available in FIFO to read, the block waits for infinite time until the data is available to read.

  • Blocking mode with Timeout - Select the Wait until data received parameter and set Timeout to any finite value greater than 0. In this mode, if data is not available in FIFO to read, the block checks the FIFO status until the timeout value is reached. If data is not available in FIFO to read within that time, then the SCI Receive block outputs its status as timeout.

  • Non-Blocking mode - Do not select the Wait until data received parameter. In this mode the SCI Receive block reads the data if the data is available in FIFO; otherwise the block outputs its status as Data not available.

In order to receive data of length more than the FIFO length, use either blocking mode or blocking mode with timeout. This ensures extra time to get the remaining data in FIFO after reading the entire FIFO.

In blocking mode with and without timeout enabled, you might encounter task overrun as it waits for the data to read.

6. 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 model.

open_system('c2000_host_serial_comm.slx');

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

3. Configure the device for Host Serial Setup, Host Serial Transmit, and Host Serial Receive blocks. Ensure that you set the baud rate to 115200 in the Host Serial Setup block.

4. Set the Stop time to Inf and click on Run drop-down and enable the Simulation Pacing in order to ensure real time communication with target.

5. Click Run.

6. Compare the serial data received from the target hardware and transmitted from the host.

Task 2 - Serial Communication between Host Computer and Target Hardware Using MATLAB Script on Host

In this task, you will transmit uint8 data from the host to the target hardware using a MATLAB® script on the host. When the target hardware receives the data on interrupt, it transmits the same data back to the host. The host then displays the received data in the MATLAB command window.

Target Model

1. Open the target model.

open_system('c28x_sci_comm_interrupt.slx');

2. The example model is configured for the TI Piccolo F28069M 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 > SCI_A and ensure that you set the Baud rate to 115200.

4. Target hardware receives the data on interrupt. SCIA_RX is used to receive on interrupt level 1.

5. Following are the SCI block configurations for the target model. Double-click on the blocks to open block parameter configurations. Follow the section Things to consider from Task 1. Ensure that the specified parameter values are the same if you want to run this example for other hardware board. In this example, the c28x_sci_comm_interrupt model is configured to Wait until data received with timeout for blocking mode.

6. On receiving the new data, an interrupt is triggered, and the target hardware transmits the received data.

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

Run on Host Using MATLAB Script

1. To run the model on host using MATLAB script, use COM port as an input argument and baud rate as an optional input argument. If baud rate is not provided, then by default a 115200 baud rate is used.

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

3. Run the following command at the MATLAB command prompt. Provide the COM port number of your computer. For example,

c2000HostSCICommunication('COM7', 115200);

4. Provide uint8 data as an input in response to the prompt.

5. Observe that the same data is received in the MATLAB command window.

Other Things to Try

More About