I bought a Raspberry Pi to work together with my rooms moodlight. The current system uses an FTDI USB to RS485 converter cable with a full-blown linux PC pushing 1Mbps of data over that to drive the animations. I intended to replace that system with a Raspberry, seeing as it already has a UART on-board and would only need a small RS485 chip to drive the bus.
Unfortunately, out of the box the Raspberrys UART can only push 115200baud, and it spits out a shitload of debug data on the serial lines.
Here’s what I did to allow it to use the UART for other things, and to drive the UART at 1Mbps 🙂
The limiting factor on the UART speed is that UART Clock. It only allows baudrates of UART_CLK/16, and the clock is set to 3Mhz by default, limiting it to 187500baud. To drive 1Mbps, we need a UART-clock of at least 16Mhz. To do this we need to:
- Set configuration parameters in /boot/config.txt
- Update /boot/start.elf to the latest version. (The version shipped with Debian doesn’t support the init_uart_clock option)
- Compile a kernel that is aware of the new uart_clock.
Line that needs changing: https://github.com/raspberrypi/linux/blob/rpi-patches/arch/arm/mach-bcm2708/bcm2708.c#L184
This should then allow you to set the baudrate higher, to test run ‘sudo stty -F /dev/ttyAMA0 1000000’. If that runs without problems, it’s probably OK. You can test some more with ‘sudo bash’, and then ‘echo BOO > /dev/ttyAMA0’ and see if an attached FTDI device picks it up at 1Mbps.
Next up is making sure nothing else is using the serial line.
- Edit /boot/cmdline.txt and remove all options mentioning ttyAMA0.
- Edit /etc/inittab and comment out any lines mentioning ttyAMA0, especially the getty one. (source: http://baldwisdom.com/preparing-for-a-la-mode-raspberry-pi-and-arduino/)
Done! Now all that’s left is writing code to actually push something over that line and wire up a small rs485 chip 🙂