2024-04-17 09:40 PM
Hi,
I have my master and slave applications running on NUCLEO-H563ZI Boards both of which normally receive/transmit 10 bytes of data in each SPI transfer. I use SPI in DMA mode.
However, in one test case, master starts a SPI transaction for only 4 bytes i.e it calls HAL_SPI_TransmitReceive_DMA with Size as 4. So, my master sends clock for only 4 bytes even though the slave has 10 bytes of data. At this point, the Master receives 4 bytes but the HAL_SPI_TxRxCpltCallback on Slave is not called.
I am doing a GPIO Pin toggle in the callback to denote completion of the SPI transfer which is necessary for my slave application. How do I abort the SPI communication in this scenario?
I see there's a HAL_SPI_Abort_IT. Not sure how to use it. Appreciate if you would provide some insight on this.
Solved! Go to Solution.
2024-04-19 12:28 AM - edited 2024-04-19 01:54 AM
But it is how you'd synchronise the Slave to the Master - if you choose to omit it, then you have to devise some other sync scheme.
The fundamental issue with omitting NSS is, exactly, that you lose this synchronisation!
2024-04-17 11:00 PM
Hi,
why not always TransmitReceive 10 bytes (even if only 2 or 4 used, others 0 or FF) ?
Then no problem with "unknown" size .
2024-04-18 12:24 AM
My test case is for this specific scenario:
Slave transmits 10 bytes but Master should send clock only for 4 bytes. In this case I expect, master to receive the requested 4 bytes and spi communication b/w them to be aborted. And, in both Master and Slave callbacks, I have a GPIO Toggle to indicate SPI transfer completion.
However, what is happening is master receives 4 bytes and master's gpio toggles but on slave, the callback is not hit and gpio is not toggled.
How should I abort my slave in a case where master sends less than required clock pulses?
2024-04-18 12:42 AM
How the slave should know : now only 4 byte coming ?
Maybe you could use just the timeout :
HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
set to 10 ms or so, then you get 10 bytes - or timeout , then you (slave) check, what you got.
2024-04-18 01:05 AM
Do you use the NSS (aka Chip Select) signal?
That's what should signal the slave that the Master has ended the transaction.
2024-04-18 09:13 PM
No, this is a blocking API and is not suited to my application.
2024-04-18 09:48 PM
The STM H5 manual says, SS pin is optional for single master and single slave.
2024-04-19 12:28 AM - edited 2024-04-19 01:54 AM
But it is how you'd synchronise the Slave to the Master - if you choose to omit it, then you have to devise some other sync scheme.
The fundamental issue with omitting NSS is, exactly, that you lose this synchronisation!