Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file main.cpp 00004 * @date February 06, 2020 00005 * @brief mbed test application - Esmacat Shield(EASE) working together with 00006 * Base Board with Arduino UNO form factor as EtherCAT slave. 00007 * With the successful execution of this code the LED on EASE should 00008 * blink. It should also estabilish data transfer between the EtherCAT 00009 * Master of Esmacat on the PC. 00010 * For further information please refer to the tutorials at 00011 * https://www.esmacat.com/tutorials 00012 ****************************************************************************** 00013 00014 Copyright (c) 2020 https://www.esmacat.com/ 00015 00016 Licensed under the Apache License, Version 2.0 (the "License"); 00017 you may not use this file except in compliance with the License. 00018 You may obtain a copy of the License at 00019 00020 http://www.apache.org/licenses/LICENSE-2.0 00021 00022 Unless required by applicable law or agreed to in writing, software 00023 distributed under the License is distributed on an "AS IS" BASIS, 00024 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 See the License for the specific language governing permissions and 00026 limitations under the License. 00027 00028 EsmacatShield.h - Library for using EtherCAT Arduino Shield by Esmacat(EASE). 00029 Created by Esmacat, 01/22/2020 00030 00031 ******************************************************************************* 00032 * @file EsmacatShield.h 00033 ******************************************************************************* 00034 */ 00035 #include "mbed.h" 00036 #include <EsmacatShield.h> //Include EsmacatShield Library 00037 00038 00039 int counter; 00040 int16_t v[8]; //an array of integer is declared for reading the 00041 //data packet of EtherCAT from EASE 8 registers 00042 Serial pc(USBTX, USBRX); // Configuring the serial port to host PC 00043 00044 DigitalOut selectPin(D10); // D10 is used to drive chip enable low 00045 SPI spi(D11, D12, D13); // mosi, miso, sclk 00046 00047 00048 int main() 00049 { 00050 00051 EsmacatShield slave(spi, selectPin); //Create an Esmacat slave object with defined 00052 // spi and chip SelectPin 00053 00054 slave.setup_spi(); //Setup SPI for EASE 00055 00056 while(1) 00057 { 00058 slave.get_ecat_registers(v); //read all registers 00059 slave.write_reg_value(0,counter++, true); //Write register data (register,value, led_on) 00060 wait_us(1000000); //sleep for 1000 ms 00061 slave.write_reg_value(0,counter++, false); //Write register data (register,value, led_on) 00062 wait_us(1000000); //sleep for 1000 ms 00063 pc.printf("Next Iteration \n"); 00064 for (int i=0;i<8;i++) //Print out read registers to host PC terminal 00065 { 00066 pc.printf("%d",i); 00067 pc.printf(" "); 00068 pc.printf("%d",v[i]); 00069 pc.printf("\n"); 00070 } 00071 00072 } 00073 00074 }
Generated on Wed Jul 13 2022 06:02:39 by
1.7.2