Build an EtherCAT Slave

Dependencies:   EsmacatShield

Quick Build EtherCAT Slave

Esmacat is an easy yet powerful EtherCAT solution for robot mechatronics developed by Harmonic Bionics. It provides a full EtherCAT hardware and software solution for Master and Slave devices which allows developers to set up and run an EtherCAT application within minutes. It also supports Power-over-EtherCAT (POE) technology which allows high-speed communication and logic-power supply over a single Ethernet cable simplifying the cabling and wiring needs of the system significantly.

EtherCAT Arduino Shield by Esmacat (EASE) is a shield which can be used to build a Slave device. It stacks onto Mbed boards with form factor of Arduino UNO. The Mbed Base board communicates with EASE over SPI. EASE communicates with the Master over EtherCAT. Multiple EASE boards can be connected with Ethernet cables in a daisy-chain topology.

Product Page

Buy this Product

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

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

Information about the hardware needs and setup is provided in the link below. https://os.mbed.com/users/pratima_hb/code/EASE_Example/wiki/Hardware-Setup

Information about the structure of the system and it's software is provided in the link below. https://os.mbed.com/users/pratima_hb/code/EASE_Example/wiki/Software

Committer:
pratima_hb
Date:
Thu Feb 06 22:33:12 2020 +0000
Revision:
1:ee9b73e47960
Parent:
0:ba190577ec8a
Updated the Example as per the datatype updates in the EsmacatShield Library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pratima_hb 1:ee9b73e47960 1 /**
pratima_hb 1:ee9b73e47960 2 ******************************************************************************
pratima_hb 1:ee9b73e47960 3 * @file main.cpp
pratima_hb 1:ee9b73e47960 4 * @date February 06, 2020
pratima_hb 1:ee9b73e47960 5 * @brief mbed test application - Esmacat Shield(EASE) working together with
pratima_hb 1:ee9b73e47960 6 * Base Board with Arduino UNO form factor as EtherCAT slave.
pratima_hb 1:ee9b73e47960 7 * With the successful execution of this code the LED on EASE should
pratima_hb 1:ee9b73e47960 8 * blink. It should also estabilish data transfer between the EtherCAT
pratima_hb 1:ee9b73e47960 9 * Master of Esmacat on the PC.
pratima_hb 1:ee9b73e47960 10 * For further information please refer to the tutorials at
pratima_hb 1:ee9b73e47960 11 * https://www.esmacat.com/tutorials
pratima_hb 1:ee9b73e47960 12 ******************************************************************************
pratima_hb 1:ee9b73e47960 13
pratima_hb 1:ee9b73e47960 14 Copyright (c) 2020 https://www.esmacat.com/
pratima_hb 0:ba190577ec8a 15
pratima_hb 1:ee9b73e47960 16 Licensed under the Apache License, Version 2.0 (the "License");
pratima_hb 1:ee9b73e47960 17 you may not use this file except in compliance with the License.
pratima_hb 1:ee9b73e47960 18 You may obtain a copy of the License at
pratima_hb 1:ee9b73e47960 19
pratima_hb 1:ee9b73e47960 20 http://www.apache.org/licenses/LICENSE-2.0
pratima_hb 1:ee9b73e47960 21
pratima_hb 1:ee9b73e47960 22 Unless required by applicable law or agreed to in writing, software
pratima_hb 1:ee9b73e47960 23 distributed under the License is distributed on an "AS IS" BASIS,
pratima_hb 1:ee9b73e47960 24 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
pratima_hb 1:ee9b73e47960 25 See the License for the specific language governing permissions and
pratima_hb 1:ee9b73e47960 26 limitations under the License.
pratima_hb 1:ee9b73e47960 27
pratima_hb 1:ee9b73e47960 28 EsmacatShield.h - Library for using EtherCAT Arduino Shield by Esmacat(EASE).
pratima_hb 1:ee9b73e47960 29 Created by Esmacat, 01/22/2020
pratima_hb 1:ee9b73e47960 30
pratima_hb 1:ee9b73e47960 31 *******************************************************************************
pratima_hb 1:ee9b73e47960 32 * @file EsmacatShield.h
pratima_hb 1:ee9b73e47960 33 *******************************************************************************
pratima_hb 1:ee9b73e47960 34 */
pratima_hb 0:ba190577ec8a 35 #include "mbed.h"
pratima_hb 0:ba190577ec8a 36 #include <EsmacatShield.h> //Include EsmacatShield Library
pratima_hb 0:ba190577ec8a 37
pratima_hb 0:ba190577ec8a 38
pratima_hb 0:ba190577ec8a 39 int counter;
pratima_hb 1:ee9b73e47960 40 int16_t v[8]; //an array of integer is declared for reading the
pratima_hb 0:ba190577ec8a 41 //data packet of EtherCAT from EASE 8 registers
pratima_hb 0:ba190577ec8a 42 Serial pc(USBTX, USBRX); // Configuring the serial port to host PC
pratima_hb 0:ba190577ec8a 43
pratima_hb 0:ba190577ec8a 44 DigitalOut selectPin(D10); // D10 is used to drive chip enable low
pratima_hb 0:ba190577ec8a 45 SPI spi(D11, D12, D13); // mosi, miso, sclk
pratima_hb 0:ba190577ec8a 46
pratima_hb 0:ba190577ec8a 47
pratima_hb 0:ba190577ec8a 48 int main()
pratima_hb 0:ba190577ec8a 49 {
pratima_hb 0:ba190577ec8a 50
pratima_hb 0:ba190577ec8a 51 EsmacatShield slave(spi, selectPin); //Create an Esmacat slave object with defined
pratima_hb 0:ba190577ec8a 52 // spi and chip SelectPin
pratima_hb 0:ba190577ec8a 53
pratima_hb 0:ba190577ec8a 54 slave.setup_spi(); //Setup SPI for EASE
pratima_hb 0:ba190577ec8a 55
pratima_hb 0:ba190577ec8a 56 while(1)
pratima_hb 0:ba190577ec8a 57 {
pratima_hb 0:ba190577ec8a 58 slave.get_ecat_registers(v); //read all registers
pratima_hb 0:ba190577ec8a 59 slave.write_reg_value(0,counter++, true); //Write register data (register,value, led_on)
pratima_hb 0:ba190577ec8a 60 wait_us(1000000); //sleep for 1000 ms
pratima_hb 0:ba190577ec8a 61 slave.write_reg_value(0,counter++, false); //Write register data (register,value, led_on)
pratima_hb 0:ba190577ec8a 62 wait_us(1000000); //sleep for 1000 ms
pratima_hb 0:ba190577ec8a 63 pc.printf("Next Iteration \n");
pratima_hb 0:ba190577ec8a 64 for (int i=0;i<8;i++) //Print out read registers to host PC terminal
pratima_hb 0:ba190577ec8a 65 {
pratima_hb 0:ba190577ec8a 66 pc.printf("%d",i);
pratima_hb 1:ee9b73e47960 67 pc.printf(" ");
pratima_hb 0:ba190577ec8a 68 pc.printf("%d",v[i]);
pratima_hb 0:ba190577ec8a 69 pc.printf("\n");
pratima_hb 0:ba190577ec8a 70 }
pratima_hb 0:ba190577ec8a 71
pratima_hb 0:ba190577ec8a 72 }
pratima_hb 0:ba190577ec8a 73
pratima_hb 0:ba190577ec8a 74 }