14

How should you set the baud rate of the UART

Bonus question: What baud rates are available on the RPi?

Edit: Since reading up from Steve's answer, I have found that there are two UARTs available.

The mini-UART can work up to 32Mbaud, but has a small buffer and so would need a lot of CPU to keep up.

There is also a more fully featured UART with bigger buffers, I haven't found the minimum/maximum speed for it yet.

John La Rooy
  • 11,947
  • 9
  • 47
  • 75
  • Do you want to set the baud rate at run time, to interface with another device, or at boot time, so you can log in to the Pi over its serial port? – Malvineous Jul 16 '12 at 12:46
  • @Malvineous, Boot time is ok, but runtime is useful too. I am interested in talking to other devices. – John La Rooy Jul 17 '12 at 01:41

2 Answers2

10

According to Farnell's Quick Start Guide, the default baud rate is: 115200. A fairly detailed discussion of the UART settings and capabilities can be found in this blog post More on Raspberry Pi serial ports. More specific implementation details/challenges of working with the serial port can be found in the blog post Getting my Raspberry Pi set up for high-speed serial UART communication.

You don't mention which distribution you are running, but assuming you are running Debian you can set the baud rate by doing the following:

Note the Raspberry Pi uses the UART for Console Messages (including bootup messages) and getty so you can login via serial. To use this serial port for your own uses you will need to disable these services.

To change the console baudrate, edit /boot/cmdline.txt relacing 115200 with your desired baud rate (note this is all one line).

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

then edit /etc/inittab to change the baudrate of the getty (you should find a line like the following with the baudrate of 115200, change that to your desired baud rate)

2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

and, remember to watch your pin voltages to avoid damage to you Pi.

Additional References:

http://www.andremiller.net/content/raspberry-pi-and-arduino-via-gpio-uart

Steve Robillard
  • 34,687
  • 17
  • 103
  • 109
3

This thread has a solution for an arbitrary (non-standard) baud rate: https://stackoverflow.com/questions/12646324/how-to-set-a-custom-baud-rate-on-linux/21960358

Doing POSIX manipulations first, then this to set the custom speed, works fine on the built-in UART of the Raspberry Pi to get a 250k baud rate. So as well as the POSIX standard rates, you can have pretty much any integer factor of 16M, up to at least 1M (http://fw.hardijzer.nl/?p=138 for very high speed stuff)