Page 1 of 1

EasyCat-EtherCat component

Posted: Thu Mar 21, 2024 12:34 pm
by talig
Hi!

The "Initialise" function never returns true.

The device does not reply.

After investigating with a logic analyzer,

I think the problem lies in the "Read Register Direct" function and the way you try to read from the device.

I noticed that
the trailing bytes you send after "command" and "address" bytes are all "0x00".

The device needs those bytes to be "0xFF" ,datasheet calls them "dummy bytes"

Please take a look at the code below:




//---- read a directly addressable registers -----------------------------------------------------

unsigned long EasyCAT::SPIReadRegisterDirect (unsigned short Address, unsigned char Len)

// Address = register to read
// Len = number of bytes to read (1,2,3,4)
//
// a long is returned but only the requested bytes
// are meaningful, starting from LsByte
{
ULONG Result;
UWORD Addr;
Addr.Word = Address;
unsigned char i;

SCS_Low_macro // SPI chip select enable

SPI_TransferTx(COMM_SPI_READ); // SPI read command
SPI_TransferTx(Addr.Byte[1]); // address of the register
SPI_TransferTxLast(Addr.Byte[0]); // to read, MsByte first

for (i=0; i<Len; i++) // read the requested number of bytes
{ // LsByte first
Result.Byte = SPI_TransferRx(DUMMY_BYTE); //
} //

SCS_High_macro // SPI chip select disable

return Result.Long; // return the result
}





Best regards
George