36.1. ECAT_IO
36.1.1. 1. Overview
The ECAT_IO example demonstrates the steps to implement an ECAT digital IO slave station with the slave stack code (SSC).
Input IO(2bit): SW6
Output IO(2bit): LED8/LED3
RUN LED: LED7
ERR LED: LED6
36.1.2. 2. Prepare
36.1.2.1. 2.1 Hardware
HPM6E00EVK(RevA)
PC with Ethernet port
TWinCAT3 software has compatibility issues with PC network cards. some supported Intel network cards
36.1.2.2. 2.2 Software
TwinCAT3.1(Build 4024.56)
SSC Tool(SSC Version: 5.13; Config File Vers: 1.5.3.0)

36.1.3. 3. Project Setting
36.1.3.1. 3.1 EEPROM Emulation Setting
The default setting is to use Flash to simulate EEPROM
36.1.3.2. 3.2 Using actual EEPROM
set the “ESC_EEPROM_EMULATION” and “CREATE_EEPROM_CONTENT” under the “Hardware” attribute to 0 in SSC Tool, then generate the slave protocol stack code.
Modify
CMakeLists.txtcontext to “set(CONFIG_EEPROM_EMULATION 0)”.
36.1.4. 4. Generate EtherCAT slave stack code
Due to licensing issues, HPMSDK does not provide EtherCAT slave protocol stack code (SSC). Users have download the SSC Tool from Beckoff’s official website and generate the slave stack code according to the steps.
36.1.4.1. 4.1. Download SSC Tool
EnterETG Download website, input “SSC” to fliter resource.

To download, you need to provide an ETG member account and a valid vendor ID
Download and install SSC Tool
36.1.4.2. 4.2 SSC Tool import configuration files
Open SSC Tool, click Tool->Options

click Configurations, import configuration file(<hpm_sdk>/samples/ethercat/ecat_io/SSC/Config/HPM_ECAT_IO_Config.xml)

36.1.4.3. 4.3 SSC Tool create new project
click File->New

Click Custom option, and select HPMicro ECAT Digital IO
from the drop-down list 
Save project, specify the file path

import application - Click Tool->Application->Import, Import <hpm_sdk>/samples/ethercat/ecat_io/SSC/digital_io.xlsx
- Click OK

36.1.4.4. 4.4 Create slave stack files
Click Project->Create new Slave Files

Specify the output path, the output source folder have to set to <ecat_io sample path>/SSC/Src, if other path, have to copy generated SRC folder to <ecat_io sample path>/SSC/Src

36.1.5. 5. TwinCAT Project setting
36.1.5.1. 5.1. Add ESI file
Copy the generated (ECAT-IO.xml) by SSC tool in previous steps to TwinCAT(C:\TwinCAT\3.1\Config\Io\EtherCAT).
36.1.5.2. 5.2 Create Project
Open TwinCAT,click File->New->Project

Click TwinCAT Project, after naming, click OK

36.1.5.3. 5.3 Software Configuration
Update network card driver (required for first use)

clock setting The TwinCAT may report the following error during runtime, win8settick.bat needs to run with administrator privileges(C:\TwinCAT\3.1\System\win8settick.bat)
Init4\RTime:Start Interrupt:Ticker started >> AdsWarning4115 (0x1013,RTIME:system clock setup failed)

36.1.5.4. 5.4 Scan device
Right click Device, then click Scan

Choose correct network

36.1.5.5. 5.5 Update EEPROM context
Double click on the scanned device, click Online, right clickBox, then click EEPROM Update。
For cases where the EEPROM content is empty, it is not possible to find a matching Box when scanning the device. In this case, it is necessary to update the EEPROM content。
In the case where EEPROM content is empty, When ESC is powered on to load EEPROM data, a checksum error will occur, which will cause PDI to not work. At this time, EtherCAT communication is possible and EEPROM content can be updated through the main station.

chosse correct files, click OK, wait for completion

Reset the board, delete the scanned devices and rescanning

36.1.5.6. 5.6 IO Control
Input IO, change DIP switch, “InputCounter” value change in TwinCAT

Output IO, write “OutputCounter” value in Twincat, Output LED change

Check RUN LED and ERR_LED status
36.1.5.7. 5.7 DC setting
double clcik “Box”, click “DC”, click “Advanced Settings”

Set mode to “DC-Synchron”, set Shift Time(Usually 20% to 30% of Sync Unit Cycle time)

double click “Device”, click “EtherCAT”, click “Advanced Settings”

click “Distributed Clock”, choose “DC in use”, click “OK”

Restart TwinCAT

36.1.6. 6. Running the example
After the project is running correctly, the serial terminal will output the following information, and the input-output IO status corresponds to the TwinCAT project configuration:
EtherCAT IO sample
EEPROM loading with checksum error.
EtherCAT communication is possible even if the EEPROM is blank(checksum error),
but PDI not operational, please update eeprom context.
or
EtherCAT IO sample
EEPROM loading successful, no checksum error.