Build an EtherCAT Slave

Dependencies:   EsmacatShield

EASE_Example

Table of Contents

  1. EASE Example Application

EASE Example Application

EASE uses SPI communication for reading/writing a data packet so, any Mbed Board with form factor of Arduino UNO supporting SPI can be used for EASE. This section presents the EsmacatShield library with an example application for Mbed platform.

  1. Login to your Mbed account
  2. Right click on “My Programs” -> Import Program from URL – enter https://os.mbed.com/users/pratima_hb/code/EASE_Example/
  3. This will add the EASE_Example in your “My Programs”.
  4. Verify the code using the "Compile" button on the top left. The code should compile successfully.
  5. Download the binary generated on the Mbed base board by dragging dropping it to the USB mounted on the PC. For this step, the Mbed board should be connected to your PC with a USB cable.
  6. Once the binary file is successfully uploaded, press the reset button on the Mbed board, the program should automatically run.
  7. Once the program is uploaded on the board the, the board should be powered by VIN pin of the EASE. Unless you need the USB cable connected to the PC for Serial communication, you may remove the cable from the Mbed board. Some Mbed boards have jumpers on the board for VIN power selection. Please make sure you read the user manual of the Mbed base board to correctly connect the jumpers.

With all the hardware set-up and powered ON, and with the Esmacat Master code running on the PC. The following can be observed on the PC terminal

  • The time that elapses between each iteration is 25 ms (set in ESMACAT_TIME_PERIOD_US)
  • The value read (set by the Mbed application over SPI) is incrementing once per second
  • The values that are being written to all the registers in the EtherCAT slave are also being incremented.
  • The PWR_LED turns on as the Slave is powered.
  • The EtherCAT LED will be solid green as the EtherCAT communications are working as expected.
  • The USR_LED is set to blink by the Mbed application at a 1s time period.

https://os.mbed.com/media/uploads/pratima_hb/ease_example_running.png

Some explanation about the EASE_Example code:

https://os.mbed.com/media/uploads/pratima_hb/ease_example_code_pic.png

  1. Include the header file of the library, mbed.h for mbed-os and EsmacatShield.h to use the EASE library.
  2. Declare an array of 16 bit integer is declared for reading the data packet of EtherCAT.
  3. D10 pin is defined as a Digital Output pin. This pin will be used as chip select pin for the SPI And an SPI object is instantiated using pins D11, D12 and D13.
  4. Instantiate an EsmacatShield object. The SPI object and the chip selector pin for SPI can be selected while constructing the object. In this example, the chip selector (CS) pin is set to pin 10. If there is conflict with another Shield for the CS pin, the pin 9 can be used by changing the CS pin selector jumper on the EASE board. After instantiation of the object the SPI communication is set up.
  5. In this step the function get_ecat_registers(v) is used to receive the data packet of EtherCAT.
  6. This code writes the constantly incrementing value of a counter to the EASE at register 0. The same command (write_reg_value) that is used to write the value, also turns on/off an LED on the EASE board with a delay of 1 s in between writes.
  7. Each value of the data packet received is then printed onto the serial monitor.

All wikipages