Page 1 of 1

SPI clock unreliable over 8MHz

Posted: Thu Oct 25, 2018 7:07 am
by livius147
Dear all,

I am currently using RPI3b and RPI3b+. I am trying to drive an external acquisition IC (ads1299) which is connected to the RPI boarda via SPI.
I tried to use the SPI @4 MHz @8 MHz and @16MHz: the system seems to be unreliable when the SCLK frequency is greater than 8 MHz.
The datasheet shows that the maximum frequency should reach 125MHz (if the source clock is @250 MHz) or 200MHz (if the source clock is @400MHz).
I acquired the SCLK waveform with my oscilloscope and it seems to be highly distorted when the frequency increases.
A similar problem has been highlighted in viewtopic.php?t=137817

Do you experienced the same problem?
Is this a problem of the PCB design?
Is there any way to remove this limitation?

Moreover I found that the SPI behavior is not always the same: if I send a few bits, the generated SCLK clock is less than the one I set. If I send many bits (about 27 bytes) the clock frequency is that I set. Is this related to the DMA/non DMA functionality? Some forums say that the linux driver use the DMA only when many bits are sent, otherwise the DMA is not used. Could it be this the problem?

Thanks in advance!

Re: SPI clock unreliable over 8MHz

Posted: Thu Oct 25, 2018 10:15 am
by HiassofT
If you see signal distortion I recommend checking your PCB layout, grounding and that you have proper connection to the SPI pins.

I just checked the SPI clock signal with the TV hat attached to an RPi3, clock is running at about 30MHz and the clock signal looks perfectly fine
sck.png (10.53 KiB) Viewed 1505 times
so long,


Re: SPI clock unreliable over 8MHz

Posted: Thu Oct 25, 2018 8:55 pm
by livius147
Thanks for your reply!

Are you recording the GPIO11 (the SCLK of the firt SPI unit), pin 23 of raspberry 3? Which code did you use to generate that waveform?
Which version of linux are you using? Raspbian with the latest kernel?
I tested spidev and bcm2845 without getting good results.


Re: SPI clock unreliable over 8MHz

Posted: Thu Oct 25, 2018 10:19 pm
by HiassofT
Yes, I probed directly at GPIO pin 23 and used the low inductance ground connection spring on my probe, connecting to GND on GPIO pin 20.

I was running LibreELEC with the TV hat driver transferring data over SPI with tvheadend accessing it, so basically no special software - you'll get the same thing with the TV hat on stock Raspbian.

If your waveform isn't clean it's almost certainly an electrical issue and has nothing to do with software. You'll get away with almost any mistake at 1MHz, but 10MHz and above is a completely different world (actually it's more about signal rise and fall time than frequency) - flying wires and breadboards won't do it there anymore.

If you're new to this area I recommend reading "High Speed Digital Design: A Handbook of Black Magic". It is very understandable and has tons of practical tips that'll help you get circuits running at 10MHz and way up operating properly. Just skip all the math sections, that stuff is a lot harder to digest.

so long,