cancel
Showing results for 
Search instead for 
Did you mean: 

How to reduce jitter in SPI (register mode)

Roshan
Associate III

Hi all, I am using register mode SPI for communication purposes,

clock is 210Mhz

interrupt is for every 4khz

initialized SPI with HAL format

SPI data rate: 35MBps

when I send data through SPI I can find some jitter inside it. But when I drive the same signal using HAL it doesn't have any jitter. Since HAL uses a lot of timing I can't use the HAL functions, please can anyone help me with this.

I am sending 2 data,8 bits long and this is running in the interrupt. so I am sending SPI as follows.

Thanks in advance.

*(volatile uint8_t*)&SPI1->DR = Wave[0];
*(volatile uint8_t*)&SPI1->DR = Wave[1];							
while(SPI1->SR &= SPI_SR_BSY) {}

4 REPLIES 4
TDK
Guru

> when I send data through SPI I can find some jitter inside it.

Explain what you mean by jitter. A screenshot or scope/logic analyzer picture would be best.

> while(SPI1->SR &= SPI_SR_BSY) {}

Probably what you intended is this:

while(SPI1->SR & SPI_SR_BSY) {}

Since SR is mostly read-only, this probably isn't causing an issue.

You're waiting for the SPI to finish its transmission. It's going to be idle between that point and the next write to DR. If you want no interruption, instead only check to see if DR has room for additional bytes (TXE flag, see reference manual for details).

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

Which MCU? There different generations of spi macrocells

Roshan
Associate III

@TDK​ Thank you for the response. I figured out the jitter problem.

If I wait till SPI to finish transmission, it takes more time (76µs extra) for CS to go high (output is very consistent). I am running this system in 30Khz cycle time. so timing is really a big issue.

But if I ignore SPI waiting time and if I make CS high soon after the data transmit. In oscilloscope, it gives the perfect wave pattern, every bit is received, nothing is missed. But the output in some cases is not consistent. Is there any method to reduce the timing for the SPI waiting method?

And if I implement this SPI in DMA will it have an advantage in the form of SPI data quality.

Thank you

Roshan
Associate III

Stm32F74xxx