2020-02-14 05:24 AM
I am working with the STM32F7 microcontroller and I would like to be able to send/receive 32-bit packets across an SPI-slave that is not using DMA. Will this be possible even if I can't guarantee to fill/empty the SPIx->DR register within a certain amount of time? (There are control pins that prevent several 32-bit packets from being transmitted before the previous one has been handled.) I am hoping that I can prepare the packet to be sent by assigning data (upper and lower words of 32-bit packet, respectively) to SPIx->DR twice, the first assignment will result in the upper word being fed into the FIFO and the second assignment will store the lower word in the SPIx->DR-register. Likewise, to retrieve the received 32-bit packet I would read SPIx->DR twice and then assemble the two (upper and lower) 16-bits words into a 32-bit word. Is this doable or have I misunderstood how the internal of the SPI-module works?
2020-02-14 06:44 AM
Assuming your SPI 32 bit RX and TX FIFO are empty, then preload the TX FIFO with the 32 bit data to be sent, in theory and not looking beyond this 32 bit transfer, you should be fine.
2020-02-14 06:47 AM
Yes, it should work. The FIFO can hold 32 bits. I would do something like this on the slave side
On the master side, just look for edges on the control line, using an EXTI or a timer input channel, polling a status bit or enabling the interrupt.
This way, there are no events that need immediate attention either from the master or from the slave.
2020-02-14 07:49 AM
Ok, this sounds good. Could I perhaps even make the packet size 6 bytes then?
2020-02-14 08:43 AM
More than 4 bytes would require DMA or a low latency interrupt handler. I don't think there is a way around that.
2020-02-14 11:05 AM
For a high bitrate SPI bus, DMA in cyclic mode with some little SW tricks gets an SPI Slave more efficient...
Otherwise, FIFO is 32 bit, you get interrupt once the first word is loaded to the DR, so if you can refill the DR before the FIFO gets empty by interrupt in worst case scenario, you will get the yes/no answer.