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.

CCS/MSP432P401R: spi slave determine cs signal

Part Number: MSP432P401R

Tool/software: Code Composer Studio

I am implementing SPI Slave with TI-RTOS.
The example projects work well.

In the example project, Master and Slave send packets of the same length through the SPI_transfer () function.
If Master and Slave send different buffer length to SPI_transfer () function, example project does not work.

This is a problem for me because the project I'm implementing doesn't always send packets of the same length from the Master.
If the SPI_transfer () function is returned (block mode) or the transferCallbackFxn callback is triggered when the CS signal is deasserted, it is expected to solve the above problem, but I don't know how to implement it.

Is there an example project that solves the above problems?
Thank you for reading
  • Hi,

    We will look into it and get back to you ASAP. Please bear with us.

    Thanks,

    PM

  • Hi,

    For the TI SPI driver, you are required to specify how large each transfer is. Once you have initiated the transfer, then the SPI driver will wait for all of the specified bytes to be transferred before returning.

    However there are a few options you could use to handle cases where the SPI slave doesn't initially know how much data to expect.

    First, you could set a timeout on each transfer. This can be done through the SPI driver, on SPI_open(). When you call SPI_open(), you can set SPI_Params->transferTimeout member variable. Then, when you make a blocking SPI_transfer() call, that function will return after the specified time has elapsed regardless of whether all the bytes have been transferred. In non-blocking mode, you can use a timer in your application and call SPI_transferCancel() to achieve the same effect.

    Second, you could implement a size header in your SPI data sent before the main transfer with the number of bytes that the master will clock the interface. For example, if you wanted the slave to read 100 bytes, you would first send a header byte with that length to the slave so that it can setup a 100 byte transfer, and then send the full 100 byte data buffer.

    Using the second option with perhaps a "slave ready" GPIO to signal the master when it can transfer data is probably the most elegant solution. I suggest you try implementing that in your project.

    Let me know if you need further clarification, or have further questions on the ideas above.

    Regards,

    Michael

**Attention** This is a public forum