I'm trying to create a simple EtherCat slave. The hardware I use is the EVB-LAN9252 and a NUCLEO-G491RE board. As Slave Stack I use SOES. The EtherCat SDK (slave editor) from rt-labs is used to generate the ESI file, a bin file for the EEPROM and some c files. With the slave explorer from the EtherCat SDK the slave can then be tested.
very much the same as in this project
After I built the project and started the Master (EtherCat Explorer), the slave could enter op-mode. But I couldn't read the Object Dictionary. I checked SPI and it isn't doing what I'm expecting it to do.
To check if SPI is working properly I tried to read out the BYTE_TEST register (0x64), which returns the value 0x431400 instead of 0x87654321. To read the register I used the following code (modified function from SOES to run on Cube IDE):
uint32_t lan9252_read_32 (uint32_t address)
{
uint8_t data[7];
uint8_t result[7];
memset(data, 0, sizeof(data));
data[0] = ESC_CMD_READ; //0x03
data[1] = ((address >> 8) & 0xFF);
data[2] = (address & 0xFF);
HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, RESET);
HAL_SPI_TransmitReceive(&hspi1, data, result, sizeof(data), HAL_MAX_DELAY);
HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, SET);
return((result[6] << 24) |
(result[5] << 16) |
(result[4] << 8) |
result[3]);
}
My SPI settings (STM32 operates as ful duplex master):
Data Size: 8 Bits
First Bit: MSB First
Baud Rate: 1.328125 MBits/s
Clock Polarity: HIGH
Clock Phase: 2 Edge (I tried all combinations of Clock Polarity and Clock Phase so i don't think the problem is there)
The EtherCAT Slave Controller Configuration Area of the EEPROM has the value 80 0F 00 CC 88 13 FF 00 00 00 00 80 00 00 57 00. The first Byte is the initialization value for the PDI Control register (0x140 -0x141). 0x80 sets the the Process Data Interface to SPI, so the problem can't be there either.