34

What SPI frequencies does Raspberry Pi support?

Additionally:

  • Are they all supported by the bootc.net SPI driver?
  • Are there any additinal things I should be cautious about when trying to communicate with some other chip via SPI?
ACarter
  • 2,350
  • 6
  • 25
  • 39
akavel
  • 1,216
  • 3
  • 12
  • 15

5 Answers5

39

The Raspberry Pi SPI runs at APB clock speed, which is equivalent to core clock speed, 250 MHz. This can be divided by any even number from 2 to 65536 for the desired speed. The datasheet specifies that the divisor must be a power of two, but this is incorrect. Odd numbers are rounded down, and 0 (or 1) is equivalent to 65536. A divisor smaller than 2 is therefore impossible.

This makes the frequency range be from 3.814 kHz to 125 MHz, with 32768 steps in between.

(There has been a lot of misinformation on this matter, but these results have been verified by experimentation. Please spread the word.)

Nakedible
  • 1,521
  • 1
  • 13
  • 18
7

The SPI can be run at the core clock speed or divided down for slower peripherals. The core clock is 250 MHz. The divider can be set to any power of two - from 2^0 all the way up to 2^16. This means that SPI frequencies from 3.8 kHz to 250 MHz are supported.

Sources:

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Maria Zverina
  • 5,168
  • 5
  • 30
  • 42
  • Would this be better as an edit to FarhadA's post? Or, flesh it out a bit to explain what the core clock is etc. – Alex Chamberlain Jun 28 '12 at 09:30
  • 1
    Maybe - Farhad is sourcing from datasheets for BCM2835 which is the actual SoC for RPi while my reference is for the BCM2708 which is only part of the SoC. The sources might converge ... but then again they might not. So I think it's better to preserve alternate sources for now. – Maria Zverina Jun 28 '12 at 09:39
  • 1
    Oh and area51 lists us as having 1.7 answers per question and states "2.5 answers per question is good, only 1 answer per question needs some work. In a healthy site, questions receive multiple answers and the best answer is voted to the top." :-) – Maria Zverina Jun 28 '12 at 09:41
  • I think BCM2708 is the CPU component which is part of the BCM2835 which is SoC (System on a Chip). But it's really hard to find authoritative source for this .... – Maria Zverina Jun 29 '12 at 10:37
  • 1
    Incorrect answer: 2^0 is not supported, and the divider does not need to be a power of two. – Nakedible Nov 01 '12 at 12:48
  • 1
    @Nakedible can you provide source for your statements? – Maria Zverina Nov 01 '12 at 16:27
  • 1
    The bcm2835 datasheet confirms the 2^0 point. http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf This is also confirmed by defines in the bcm2835 library. http://www.open.com.au/mikem/bcm2835/ As for the non power of two divisors, the datasheet errata mentions that possibly multiple of 2 was meant. http://elinux.org/BCM2835_datasheet_errata This was also posted on some forum that any multiple of 2 seems to work. All of this has also been confirmed by testing the SPI output on real hardware. See my answer below which specifies this exactly. – Nakedible Nov 01 '12 at 18:01
4

I have tested with the as seen on http://www.brianhensley.net/2012/07/getting-spi-working-on-raspberry-pi.html and changed the speed.

The maximum speed when the test passed is 15MHz = 15000KHz: See result:

spi mode: 0
bits per word: 8
max speed: 15000000 Hz (15000 KHz)

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

The test at 16MHz failed. André

akavel
  • 1,216
  • 3
  • 12
  • 15
andré
  • 41
  • 1
  • 1
    Mine ran ok at 32MHz = 32,000KHz. I've seen it mentioned here that this is the practical limit too. I am running the latest RPi firmware on Raspbian hard float if that makes a difference. – dodgy_coder Aug 27 '13 at 06:01
  • Having RPi 3 running that test at 60MHz successfully. – Vlad Aug 22 '19 at 14:57
  • 1
    Using the spidev library in Python 3 on a Pi3B+ to drive a Texas Instruments TDC7201 which has a spec max speed of 25 MHz, everything seems to work fine up to about 33.2 MHz but completely dies at 33.3 MHz. This appears to confirm (1) that setting 33.3 MHz does something different from setting 33.2 MHz, and (2) speeds up to at least 33 MHz work. I suspect that it's the TDC7201 dying, not the Pi. – Howard A. Landman Jun 10 '21 at 20:42
4

The datasheet of BCM2835 says the following on page 120: The value of the clock register of the SPI block contains.

BC Clock Divider SCLK = Core Clock / CDIV If CDIV is set to 0, the divisor is 65536. The divisor must be a power of 2. Odd numbers rounded down. The maximum SPI clock rate is of the APB clock.

I can't find any reference to what is the maximum frequency of the APB bus, I think that is part of the ARM11 documentation and not this SoC.

FarhadA
  • 1,837
  • 2
  • 16
  • 20
  • 1
    Thanks for the reference; I believe the page is 156? CDIV seems to be 16b wide, so goes from 1 to 65536. "Core clock" is probably the 700MHz? So we'd get range from ~10.7kHz up to the mysterious APB limit? – akavel Jun 25 '12 at 21:48
  • 1
    You are very welcome, but I am afraid this clock is not the core clock. It is the APB bus: "APB is designed for low bandwidth control accesses, for example register interfaces on system peripherals. This bus has an address and data phase similar to AHB, but a much reduced, low complexity signal list (for example no bursts). It has to support 32bit and 66MHz signals." – FarhadA Jun 25 '12 at 21:54
1

BC Clock Divider SCLK = Core Clock / CDIV If CDIV is set to 0, the divisor is 65536. The divisor must be a power of 2. Odd numbers rounded down. .....

Linguistically, 'Odd numbers rounded down' is consistent with 'power' being a typo for 'multiple' If it was intended to be a power of two, there would be no need to reference odd numbers.