# What SPI frequencies does Raspberry Pi support?

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?
-

## 4 Answers

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.)

-
I think this answer ought to be at the top. – Jon Watte Jan 9 '13 at 18:40
Are you sure about this? Gordon asserts that, while you can feed it any even number, only powers of two actually make a difference: Understanding SPI on the Raspberry Pi | Gordons Projects – scruss Feb 2 '13 at 16:45
I tested this with an oscilloscope. I think the problem with Gordon is that he uses the kernel driver, which mangles the clock speed, instead of directly commanding the processor without using the kernel driver. – Nakedible Feb 4 '13 at 14:39
This Forum-Thread provides further information to prove Nakedible's answer: raspberrypi.org/phpBB3/… – Nippey Sep 16 '13 at 13:55

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.

-
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
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

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:

-
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 9:30
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 9:39
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 9:41
@MariaZverina: oh shit, I was confused why the driver sourcefiles are marked as 'bcm2708', while RasPi is said to use BCM2835 - so you're saying these are some two related specs, which do additionally have inconsistencies??? man, that's a real wtf question to submit... raspberrypi.stackexchange.com/questions/840/… – akavel Jun 29 '12 at 10:31
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

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é

-
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 6:01