Implementing EtherCAT Slave with STM32F407 and ET1200

EtherCAT Slave Configuration

  • Create new SSC file using EtherCAT Slave Design Quick Guide and ETG2000 specification document
  • Configure SSC settings for slave implementation
  • Define EtherCAT basic data types

Code Generation Process

  1. Create SSC file (recommended version 5.12 for fewer modifications)
  2. Modify SlaveInformation section
  3. Keep Generic settings unchanged
  4. Update Hardware configuration for STM32
  5. Maintain default EtherCAT Sttate Machine
  6. Adjust Synchronisasion: Add 1ms timer for EtherCAT watchdog
  7. Modify Application: Exclude el9800app.c and include necessary headers
  8. Update ProcessData: Adjust PDO transfer addresses
  9. Configure MailBox: Set SM transfer addresses

ET1200 has 1KB memory (0x1000-0x1400):

  • 0x1000-0x11FF for mailbox
  • 0x1200-0x13FF for PDO

PDO Variable Configuration

  • Add PDO variables in Excel worksheet
  • Only 0x6000 and 0x7000 PDOs require manual mapping
  • Save configuration as 'myapp'
  • Generate EtherCAT code

STM32 Implementation

Import generated files into project and modify:

  1. Add required definitions in el9800hw.c
  2. Implement SPI, timer, and interrupt initialization
  3. Update RxTxSpiData function for SPI communication
  4. Add timer interrupt handler
/* SPI Initialization Example */
void SPI_Init_Config(void) {
    GPIO_InitTypeDef GPIO_InitStruct;
    SPI_InitTypeDef SPI_InitStruct;
    
    // Enable clocks and configure pins
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
    
    // Configure SPI pins
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(GPIOB, &GPIO_InitStruct);
    
    // SPI configuration
    SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
    SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStruct.SPI_CPOL = SPI_CPOL_High;
    SPI_InitStruct.SPI_CPHA = SPI_CPHA_2Edge;
    SPI_Init(SPI1, &SPI_InitStruct);
    SPI_Cmd(SPI1, ENABLE);
}

Master Configuration (TwinCAT 3)

  1. Place generated XML file in TwinCAT directory
  2. Create new project in Visual Studio
  3. Install network adapter
  4. Obtain license
  5. Scan devices and confirm all prompts
  6. Switch to Operational state
  7. Verify initial values and communication
  8. Test value writing functionality

For variable additions:

  • Modify XML file for all related objects (0x6000/0x7000, etc.)
  • Update myappObjects.h with matching definitions
  • Adjust PDO transfer functions in myapp.c

Note: Regenerating code with SSC and replacing specific files may be more efficient thann manual modifications.

Tags: EtherCAT STM32 ET1200 Embedded Systems Industrial Communication

Posted on Mon, 06 Jul 2026 17:02:18 +0000 by calande