2014-08-21 08:15 AM
Hi,
I'm using the STM32L053 Discovery kit, and have two board talking to each other over SPI using the example code: ''C:\STM32\STM32Cube_FW_L0_V1.1.0\Projects\STM32L053C8-Discovery\Examples\SPI\SPI_FullDuplex_ComIT'' 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? Thanks, Rob #spi-slave2014-08-22 08:35 AM
BTW, I'll be offline for a few days, but will be grateful for any help on my return.
Thanks.2014-09-01 05:52 AM
2014-09-01 07:59 AM
Hi Rob,
The STM32Cube SPI HAL API's driver are developed in a way to manage the SPI bus peripheral functionalities.The HAL_SPI_TransmitReceive_IT() API transmits and receives an amount of data (BUFFERSIZE) in no-blocking mode with Interrupt.In this case (Interrupt mode) the end of transfer of the whole data will be indicated through the dedicated SPI IRQ handler. The API doesn't manage intermediate transfer of SPI data. You can just add a simple loop within the SPI IRQ handler that checks an end of tranfer byte, fixed by the user, in order to manage the send transaction end for intermediate transfers of SPI data.Hope that may help you.With regards.