Serial Communication with CASP

 

Download Project

 

This example project demonstrates how to establish serial communication between the target board and the host (native) PC. We try to acquire analog data from the target board to the host PC through USB serial and plot the data on the host PC. We also try to control the on-board LED present on the target board from the host PC.

 

Target

Arduino Uno and Arduino Mega 2560 targets are used in this project. However, any supported boards can be used.

 

Description

Connect any sensor to the ADC pin A0 of Arduino Uno and Arduino Mega 2560 for sensing. We use the on-board LED at pin-13 for controlling. First we use Arduino Uno to communicate with the host PC through USB serial. Following are the steps to properly program the Arduino and native targets to achieve above objective.

·       Connect Arduino Uno to the host PC via a USB cable.

·       Note the serial port number to which the board is connected to the host PC, from the host operating system.

·       Run CASP and load the ‘target_model’ project. Ensure that the ‘Serial’ block is enabled with Serial1, Serial2 and Serial3 blocks disabled.

·       Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target Hardware Programmer Port’ parameter to the serial port to which the board is connected.

·       Build the model and program the board by clicking on Run button.

·       After the board is programmed, close the current project and load the ‘native_model’ project.

·       With the target board connected to the host PC, click on Home->Simulation->Configure Simulation IO menu item.

·       ‘Configure Simulation Hardware’ window will open. Change the serial port marked in the below figure (by double clicking on the item) to the port where Arduino is connected.

 

·       Click on ‘Connect Device’ button and check the ‘Online Data’ check box. The program should now communicate with the target with cycle time less than 10msecs. Target board is now available as end point ‘EP0’ to the native model. Native model can use this end point to connect to respective IOs on the target.

·       Click on ‘Save’ button to save the configuration and close the window.

·       Run the model by clicking on the Run button. A simulation panel window should open and communicate with the board. A screen shot is shown below.

·      From the simulation panel toggle the switch to control the on-board LED.

·      Connect Arduino Mega 2560 board through a FTDI USB to UART converter module as shown in the circuit diagram.

·      Repeat all the above steps with Serial1, Serial2 and Serial3 blocks enabled (one at a time).

  

Circuit Diagram

 

Model

Target Model

 

Native Model

 

References

Please go through our video tutorials, tutorial projects and CASP main documentation for getting started with CASP.