Post Go back to editing

Unable to read SPI data properly

Category: Software
Product Number: TMC5160

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

Thread Notes

  • [update] I can able to read the read only registers and values are coming properly, but when i tried to read RW (Read Write) Registers the value comes as oxoooooooo along with the status byte. Should i want to change something in the address when i use RW access registers?

  • Hello, Found that when the motor is in motion i can able to read the data properly, but when the motor is in standstill reading the register gives the value 0x00, i assume that it has to do with some register setting which can put the controller in sleep mode or similar, can anyone help on this?

  • Hi,

    I have seen this question also on our support portal also. My feeling now is, that there is some issue in the read procedure. For the driver itself, there is no difference if the motor is moving or not. There is no register that would disable read access. In X_ACTUAL, you should be able to trace the motion and see that it reaches XTARGET, once finished.