AnsweredAssumed Answered

Implementing SPI Slave with unknown data length?

Question asked by RobS on Aug 21, 2014
Latest reply on Sep 1, 2014 by Montassar BEN ROMDHANE

I'm using the STM32L053 Discovery kit, and have two board talking to each other over SPI using the example code:


I want to move on from here to develop a protocol, an have hit a snag on the slave, namely that the example code is waiting for an exact number of bytes.  If I set the slave length to 16 and the Master only sends 8, the slave waits until two transactions have occurred.

What is the correct way to get the slave to (promptly) report the transaction complete if it doesn't know in advance how long the transaction is?

What I'm looking for is something like:
HAL_SPI_TransmitReceive_IT(&SpiHandle, aTxBuffer, aRxBuffer, BUFFERSIZE)
but where BUFFERSIZE is a MAXIMUM length, not a REQUIRED length.
Since STM32Cube has given me the HAL, and the HAL is working so far, my starting point is to try using that rather than reinventing the wheel.

At the moment I have NSS in software as in the example, but I don't mind adding a hardware NSS if necessary, as there will be a hardware NSS in the real hardware.  Ideally the HAL would be telling me the transaction is complete as soon as NSS is deasserted.

Is that possible?