CASP supports exchanging data between micro-controllers using CAN communication. This example project demonstrates data communication between three micro-controllers boards using MCP2515 CAN controller modules with one of the micro-controller connected to host PC using serial communication. Analog data is acquired from the three micro-controller boards through serial communication from one of the micro-controller board and plot the data on the host PC. The model also controls the on-board LED and PWMs present on the target boards from the host PC.

Pre-Requisites

  • Arduino Nano, Raspberry Pi Pico, Vega Aries or any three micro-controller boards supported by CASP with SPI interface.
  • MCP2515 CAN controller modules – 3 No.
  • CASP software is installed along with CASP Python Libraries (optional).
  • Arduino BSP is installed.
  • The project files are located at CASP installed directory ‘CASP/support/examples/communication/9_can_bus’. These are also available for download at this link.

Connection Diagram

Aries Vega v3.0 and Arduino Nano development boards are used as the remote micro-controller boards connected to the respective MCP2515 modules. As mentioned earlier, since MCP2515 supports only SPI communication, Raspberry Pi Pico (RPiPIco) development board is used as an intermediate micro-controller between the host PC and the third MCP2515 module.

Connect the circuit as shown below. Connect any sensor to the ADC pin A0 and A1 of the Vega Aries board for sensing. We use the on-board LED at pin GPIO24 and PWM0 for controlling. Similarly, Arduino Nano A0,A1 and PMW pins 5 and 6 are used for data acquisition and control. Data from the host PC is transferred to RPi Pico through serial communication and from RPi Pico to Vega Aries and Arduino Nano through wireless communication

CASP Model for Vega Aries Board

  • Connect the target 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 ‘can_target_vega’ project. Open the workspace file ‘can_target_vega.wsp’ from CASP main window.
  • All blocks are pre-configured for proper functioning. However, user may change the configuration of any block as required. By default data encryption is disabled user may enable the same in the can block parameters.
  • For Aries Vega, SPI1 is selected for SPI communication. Choose suitable SPI interface if other micro-controller targets are used.
  • Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target 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.

CASP Model for Arduino Nano board

  • Connect the target 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 ‘can_target_nano’ project. Open the workspace file ‘can_target_nano.wsp’ from CASP main window.
  • All blocks are pre-configured for proper functioning. However, user may change the configuration of any block as required. By default data encryption is disabled user may enable the same in the can block parameters.
  • Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target 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.

CASP Model for Raspberry Pi Pico board

  • Connect the target 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 ‘can_target_pico’ project. Open the workspace file ‘can_target_pico.wsp’ from CASP main window.
  • All blocks are pre-configured for proper functioning. However, user may change the configuration of any block as required. By default data encryption is disabled user may enable the same in the can block parameters.
  • Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target 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.

CASP Model for Host Computer

  • Run another instance of CASP and load the ‘can_native’ project. Open the workspace file ‘can_native.wsp’.
  • From ‘Serial’ block parameters enter the serial port to which the Arduino Nano is connected to the PC.
  • Click on Run button to build and run the model.