Hello Team,
We have TMC5160 IC populated on the customized board with MCU controlling TMC5160 via SPI. We have built SPI Read and Write functions. using the write function we were able to write/configure all the registers properly and we can see the stepper motor responding exactly to the command sent to TMC5160. When we tried to read the register (0x21) which was written with a value (0x00FFFFFF) before the result that we get is Status Byte + 00000000. Every time we read the register we are getting proper value and this value responds to the REFL Switch (limit switch) when ever pressed. So to make it simple, register write is working properly and while reading register only status Byte comes rest of the data are 0x00000000. Attached the write and read functions code below
// SPI WRITE FUNCTION
void Write_32bitSPI_DATA (uint8_t ADDR, int data)
{
SPI_MOTOR_CHIP_SELECT ( 0x00);
Data_To_Transfer(ADDR | 0x80);
Data_To_Transfer((data & 0xFF000000) >> 24);
Data_To_Transfer((data & 0xFF0000) >> 16);
Data_To_Transfer((data & 0xFF00) >> 8);
Data_To_Transfer(data & 0xFF);
SPI_MOTOR_CHIP_SELECT (0xFF);
}
// SPI READ FUNCTION
uint8_t SPI_STATUS_VALUE1 =0;
int Read_32bitSPI_DATA(uint8_t ADDR)
{
uint32_t SPI_DATA_VALUE = 0;
uint8_t SPI_STATUS_VALUE =0;
SPI_MOTOR_CHIP_SELECT (0x00);
Data_To_Transfer(ADDR & 0x7F);
Data_To_Transfer(0x00);
Data_To_Transfer(0x00);
Data_To_Transfer(0x00);
Data_To_Transfer(0x00);
SPI_MOTOR_CHIP_SELECT (0xFF);
CyDelay(1);
SPI_MOTOR_CHIP_SELECT ( 0x00);
Data_To_Transfer(ADDR & 0x7F);
SPI_STATUS_VALUE1 = SPIM_ReadRxData();
Data_To_Transfer(0x00);
SPI_DATA_VALUE |= (uint32_t) SPIM_ReadRxData() << 24;
Data_To_Transfer(0x00);
SPI_DATA_VALUE |= (uint32_t) SPIM_ReadRxData() << 16;
Data_To_Transfer(0x00);
SPI_DATA_VALUE |= (uint32_t) SPIM_ReadRxData() << 8;
Data_To_Transfer(0x00);
SPI_DATA_VALUE |= (uint32_t) SPIM_ReadRxData();
SPI_MOTOR_CHIP_SELECT (0xFF);
return SPI_DATA_VALUE;
}
Value Written to 0x21 is 0x00FFFFFF
When reading the register 0x21 the result is 0x2D00000000
When reading the register 0x21 when REFL and REFR switch is pressed 0xED00000000