Wire
Posts: 78
Joined: Tue Sep 11, 2012 6:46 pm

What is the max clock/baud rates for SPI/I2C/Uart

Sun Sep 16, 2012 9:08 pm

Done some digging beforehand but have not found all the answers I need.

Looking to figure out the maximum clock speed / baud rate for all the hardware ports. I know the actual max speed is limited by many other factors including signal integrity and software overhead. But just trying to get a handle on the hardware maximums.

From the BCM2835 ARM Peripherals document I found the following info
http://www.designspark.com/files/ds/sup ... CM2835.pdf

Uart1 (section 2.2)
Baud rate = system_clock/(8*(divider_reg +1)
-> What is the system_clock rate on the raspberry pi?

SPI0 (section 10)
clock rate = core clock/cdiv_reg
-> What is the core clock rate on the raspberry pi?

SPI1,2 (section 2.3)
clock rate = system_clock/(2*(divider_reg+1)
-> What is the system_clock rate on the raspberry pi?

BSC (Broadcoms name for the I2C engine section 3)
clock rate = core_clock/divider_reg
-> What is the system_clock rate on the raspberry pi?
-> also the information mentions fast mode (400kHz) but looking at the clock dividers things could go much faster... Anyone tried running at high speed (3.4MHz) mode? (was a valid mode in the 2.1 spec this engine is based on)

Uart0 (section 13) sends you over to ARM PrimeCell UART from that
http://infocenter.arm.com/help/topic/co ... DI0183.pdf

baud rate = uartclk/(16*divider_reg) (note there are 2 regs for the integer and fractional dividers)
-> what is the uartclk clock rate on the raspberry pi?
-> what is the pclk clock rate on the raspberry pi?

Sounds like the uartclk and pclk rates are adjustable... Is there another document that goes over what these are used for and how to change them?

GPIO alt function matrix http://elinux.org/RPi_BCM2835_GPIOs

User avatar
Gert van Loo
Posts: 2486
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: What is the max clock/baud rates for SPI/I2C/Uart

Mon Sep 17, 2012 7:34 am

Wire wrote:..... I know the actual max speed is limited by many other factors including signal integrity and software overhead. But just trying to get a handle on the hardware maximums.
The UART and the SPI can be driven by DMA so there is no SW limitation.
The real maximum for all those interfaces is only set by the signal integrity.
This is certainly the case for I2C as it has to use pull-up resistors to get the signals high again.

I know the clocking is rather confused. I built the damn chip and I still have no idea how to control all the clocks.
The clocking structure is very complex with a limited number of resources (PLL's) which are used for a
plethora of things to drive. (A quick count shows 36! clocks being generated) There will be many cases where it is just
not possible to give you ALL the frequencies you want.
The clocking is under SW control and I have no idea what the SW does with all those clocks or how clever it is.

Wire
Posts: 78
Joined: Tue Sep 11, 2012 6:46 pm

Re: What is the max clock/baud rates for SPI/I2C/Uart

Mon Sep 17, 2012 12:05 pm

Is there any documentation on the clocking structure? Mostly just need to dig up what the defaults the Pi is using so I can set up the dividers to a reasonable values.

jeremybirch
Posts: 3
Joined: Tue Jun 05, 2012 2:36 pm

Re: What is the max clock/baud rates for SPI/I2C/Uart

Mon Oct 29, 2012 6:41 pm

I have succeeded in getting the main UART to run correctly but unfortunately its maximum baud rate is 186kbaud as it is being driven by 3MHz UARTCLK. The Datasheet implies that the "clock manager" should be used to change this frequency (I need a 4MHz UARTCLK to get 250kbaud) however the only further mention of the clock manager describes the 3 GPIO clocks, and all of these seem to be disabled by default and certainly not driving the UART with 3MHz.

Any clues which registers need to be addressed in order tyo get a 4MHz UARTCLK?

msperl
Posts: 344
Joined: Thu Sep 20, 2012 3:40 pm

Re: What is the max clock/baud rates for SPI/I2C/Uart

Tue Oct 30, 2012 7:48 am

Core clock is normally 250MHz, but you can change with your "overclocking" settings up to 500MHz.
You can also "fix" your overclocking - by which you can control the clocks (core + System) direcly by configuring them in /etc/config.txt (See also: http://elinux.org/RPi_config.txt) or run raspi-config and go to overclock to see "typical" options and what they are setting...

And from those values you control via the dividers your real clock for SPI and others.

Ciao,
Martin

User avatar
Gert van Loo
Posts: 2486
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: What is the max clock/baud rates for SPI/I2C/Uart

Tue Oct 30, 2012 8:23 am

You can not send data at that speed. The GPIO pins are no fast enough.
We tested the pins and the max frequency is around 100KHz*** but then you get more of a sinewave out instead of a digital signal.
The problem with the clock manager is that it has to drive up to 40 different clocks from four PLL's.
That often requires compromises and moving clocks around.
I have no idea how the SW does that. That is the reason why the clock manager is not described
in details as basically you are not allowed to use it your self but 'ask' the clock manager SW to do things for you.
I will ask Dom what a solution for that is

***Gert post edit: that 100KHz should be 100MHz!!!!! See two posts further.

msperl
Posts: 344
Joined: Thu Sep 20, 2012 3:40 pm

Re: What is the max clock/baud rates for SPI/I2C/Uart

Tue Oct 30, 2012 8:35 am

Well. these values are the theoretically max possible (it seems) - I should have mentioned that.

But, at least on the SPI side Clock rates between 8 and 16MHz are not having any negative impact on communicating with the attached chips (CAN Controller mcp2515 (@8MHz), Ethernet Controller enc28j60 (@16MHz) and SDCard (@16MHz)).

How far you can go for the other devices/bus types you will need to test yourself.

karlkiste
Posts: 189
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: What is the max clock/baud rates for SPI/I2C/Uart

Sat Feb 09, 2013 2:22 pm

Gert van Loo wrote:You can not send data at that speed. The GPIO pins are no fast enough.
We tested the pins and the max frequency is around 100KHz but then you get more of a sinewave out instead of a digital signal.
I've just seen a clean rectangle wave out of the TX pin at 4 megabaud, that is 2 MHz when sending "UUUUUUUUUU...."

Have you measured at RS232 levels? Level converters employ slew rate control to reduce noise emission and therefore limit the data rate to about 120kbaud. At 3.3V level, the pins have transition times of less than 20 nanoseconds and can therefore easily generate tens of megahertz's.

User avatar
Gert van Loo
Posts: 2486
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: What is the max clock/baud rates for SPI/I2C/Uart

Sat Feb 09, 2013 5:22 pm

karlkiste wrote:
Gert van Loo wrote:You can not send data at that speed. The GPIO pins are no fast enough.
We tested the pins and the max frequency is around 100KHz but then you get more of a sinewave out instead of a digital signal.
I've just seen a clean rectangle wave out of the TX pin at 4 megabaud, that is 2 MHz when sending "UUUUUUUUUU...."

....
Yes! big gaffe from my side it should have said 100MHz. not KHz.
I was only off by a factor 1000!

nielsvh
Posts: 4
Joined: Tue Oct 15, 2013 4:59 pm

Re: What is the max clock/baud rates for SPI/I2C/Uart

Tue Oct 15, 2013 5:15 pm

After reading around, I did some testing to see what the maximum achievable baud rate is. Using the latest stable raspbian build (3.6.11+) and editing init_uart_clock in /boot/config.txt, I was able to get up to 4Mbaud read speeds. However, past that point it seems that the linux OS stops support, as bits/termios.h has __MAX_BAUD at 4Mbaud (http://repo-genesis3.cbi.utsa.edu/cross ... .html#:172).
I would think that going up to 15.6Mbaud would be feasable, considering that baud_rate=250MHz/(8*(1+baud_reg)), but I'm at a loss as to what to do to get past the 4Mbaud limit.

karlkiste
Posts: 189
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: What is the max clock/baud rates for SPI/I2C/Uart

Wed Oct 16, 2013 7:35 am

Receiving like

cat /dev/ttyAMA0 >/file_on_ramdisk

I could store data with up to 1 MBaud. At 2 MBaud, data was partly corrupt without any error meaasge. I did not use handshake, which might have helped to get correct data, but which might slow down transmission speed a bit.

The data was sent from an OS-less microcontroller, so I'm pretty sure that the errors occurred on the receiving side.

So, if even receiving with 2 MBaud is unreliable, I doubt that it is of much use to push speed beyond 4 MBaud.

If you need to transfer data faster than 1 MBaud, I'd suggest USB or network, which has DMA capability and can therefore better cope with large amounts of data than the UART does.

nielsvh
Posts: 4
Joined: Tue Oct 15, 2013 4:59 pm

Re: What is the max clock/baud rates for SPI/I2C/Uart

Fri Oct 18, 2013 4:26 pm

I've been looking into DMA on the Pi and cannot make heads nor tails from anything I've read. Any pointers to how to access DMA? I've never done any USB programming before, which may also be limiting my overall understanding of the articles I've google'd.

karlkiste
Posts: 189
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: What is the max clock/baud rates for SPI/I2C/Uart

Fri Oct 18, 2013 6:23 pm

Well, I'm not too close to the hardware either, I let the device drivers do their work... SPI, USB and network can (and probably do) use DMA. The UART can explicitly not use DMA, according to the Broadcom ARM peripherals paper.

Return to “Interfacing (DSI, CSI, I2C, etc.)”