This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Multi-Buffered SPI question

Other Parts Discussed in Thread: TMS570LS20216, HALCOGEN

hello,experts:

    I'm using TMS570LS20216 to control a SPI device,i use the multi-buffered SPI mode,and this is my SPI5 HALCoGen configuration(Baudrate:50KHz,Charlen:8):

   and the following picture is my SPI device data frame specification:

   when i read the SPI device data reference  the SPI Example code like this:

   spiSetData(spiREG5, 0, m_data_out);
   spiTransfer(spiREG5, 0);
   while(!(spiIsTransferComplete(spiREG5, 0))){};
   //sysDelay_us(700);
   spiGetData(spi, 0, m_data_in);

   the data read from the SPI device is not correct(CRC error),but when  add the time delay(sysDelay_us(700)),the read data from the SPI device is correct(CRC passed).So, i check the spiIsTransferComplete() API function,it define like this:

  int spiIsTransferComplete(spiBASE_t *spi, unsigned group)
{
    return (spi->INTFLGRDY >> group) & 1;
}

  It check the INTFLGRDY flag which descritpion is : "Transfer-group interrupt flag for a transfer-completed interrupt."

  So, is the "transfer-completed" means all datas in the buffer has shifted out from the RX shift register?If not, how to config the register in HallCoGen and wich bit shoud i check to ensure my SPI data frame(3 bytes) has shifted out from the RX shift register so i can read the D0~D7 + CRC correct? 

  Thank you very much.

  • Max,

    By looking your code, I assume that the first time your run your code, on the first transfer, the CRC should be correct.
    It's only on the next transfer that you are seeing the CRC error.

    The spiIsTransferComplete() API check for the end of transfer flag to be set, but does not clear it.
    On the next transfer, this spiIsTransferComplete()  call will return immediately, because the flag is set by the previous transfer.
    When you add the delay routine, basically, you are waiting for the transfer to be done and than read the data.

    The solution is to add this statement after the call of spiIsTransferComplete():

    spiREG1->INTFLGRDY = 0x0001;     // Clear the INTFLGRDY flag.

    Please have a try and let me know.

    Regards,

    Jean-Marc

  • Hi, Jean:

        It works, thank you very much.