AnsweredAssumed Answered

SPI slave with variable message length

Question asked by antoine monmarché on Jun 7, 2019
Latest reply on Jun 12, 2019 by Razvan-nicolae Tilimpea



I'm using S32K148EVB board.
The SW uses:
- FreeRTOS
- SPI slave (spi_pal with lpspi0 using DMA)
- additional Output pin PTA30 for Spi Slave to request the master to start SPI communication
- additional Input pin PTA6 for Spi Slave, connected to SPI CS pin and configure as interrupt


Sending data from Slave to Master works fine.
Detecting CS pin change with PTA6 Interrupt works fine.

Our application protocol starts with 1 byte with value 0x55 and as variable length (with lenght indicated in the payload).

For reception I'm calling API SPI_SlaveTransfer(SPI_INSTANCE, slave_send, slave_receive, BUFFER_SIZE) and wait for the master to poll the SPI.


The issue is that we don't know in advance the size of the packet that the master will send.
So the spi callback will not be triggered unless all the bytes are received.

What would be the best solution for our case (being able to receive any length, any time)? Should we wait for CS to be disabled before reading the DMA rx buffer?

I would like to avoid modifying as much as possible the spi_pal and lpspi drivers provided in the SDK.

There seems to be no clear answer from all the NXP Community thread I read:

my first thread: