cancel
Showing results for 
Search instead for 
Did you mean: 

Hello guys, so i'm using the SPI protocol on my stm32F407, i'm trying to send a 32 bit data but the data frame is either 8bit or 16bit. i'm testing a simple Full-duplex example using SPI1. How can i remove the Delay between bytes?

Sbhy.1
Associate II
 
2 REPLIES 2
TDK
Guru

A delay between bytes is typically not an issue for SPI communication.

To remove it, you could send using DMA, or slow down you clock speed.

If you feel a post has answered your question, please click "Accept as Solution".
berendi
Principal

Although the STM32F4 series SPI controller has no FIFO, there is still a single data unit worth of buffer. If SPI is idle and data is written into SPIx->DR, it is immediately transferred to the internal shift register, TXE status is set, and DR can be written once more. If the software manages to write new data into DR before the previous one is completely shifted out, there should be no delay.

0693W000001qR5uQAE.png

In the typical clock configuration the SPI bitrate is 1/4 of the core clock, so when using 16 bit frames the software has 64 cycles to update the DR register. This can be achieved in a software loop, or using DMA, but it would need a very tightly optimized interrupt handler.

It is not worth setting up a DMA channel for transmitting 2x16 bits, you can just write the data register two times, checking TXE between them. Unless an interrupt happens exactly after you write DR the first time, there should be no delay.

Of course if you are using some library instead of writing the registers directly, the story is quite different.