Raspberry Pi GPIO Pin Alternate Functions
The general-purpose input/output (GPIO) pins can be switched between input or output and have a pull-up or pull-down resistor enabled, but there are a host of other peripherals in the Raspberry Pi chip that can be switched to these pins. You can see the basic arrangement for one pin, GPIO 18.
All the other pins have a similar arrangement but with different blocks to select from. The numbers on the switch are the three-bit register value that have to be set in the collection of alternate function select registers. Note that the Alt numbers have little relationship to the bit patterns you actually set.
Although there are 54 GPIO lines in the Raspberry Pi’s processor, only 28 are brought out to the P1 connector on the board (less on the non-plus models); the rest are used for actually making the processor act like a computer (things like the SD card, USB connector, and LEDs). On the B+ and A+ models, you have the first 28 GPIO pins; on earlier models, you have a subset of these. Most diagrams you find give you only a selection of these alternate functions. Here, you can see all the alternate functions and where they appear on the GPIO connector.
The first thing to spot is that there are two types of “nothing here”: One is blank and the other is labeled as <reserved>. It’s likely that these reserved functions are used for factory testing of the chip or for functions not disclosed in the data sheet. The blank ones are simply not implemented.
For the full gory tale, the BCM2835 ARM Peripherals document is where you want to look, but here’s a quick look at some of the functions:
ALT 0: Where most of the interesting and useful alternate functions are as far as the Raspberry Pi is concerned. The SDA and SCL 0 and 1 are the two I2C buses, and the TXD0 and RXD0 are the serial connections. The GPCLK lines are a general-purpose clock output that can be set to run at a fixed frequency independent of any software. The PWM pins provide the two pulse width modulated outputs; the SPI 0 is the serial peripheral interface bus lines. Finally, the PCM pins provide pulse code modulated audio outputs.
ALT 1: The pins are used as a secondary memory bus. Due to the design of the Raspberry Pi, this is of no use at all.
ALT 2: The only ALT 2 pins brought out the to the GPIO pin header are reserved.
ALT 3: The most useful pins here are the CTS0 and RTS0 lines; these are handshaking lines for the serial module if you need them. The BSC lines are for the Broadcom Serial Controller, which is a fast mode I2C-compliant bus supporting 7-bit and 10-bit addressing and having the timing controlled by internal registers. The SD1 lines are probably for the control of an SD card, but the BCM2835 ARM Peripherals document makes no other mention of it. It isn’t the way the Raspberry Pi accesses the SD card anyway.
ALT 4: The SPI 1 lines are a second SPI bus. And the ARM pins are for a JTAG interface. JTAG is a way of talking to the chip without any software on it. It’s very much used for the initial tests on a system during development, although it can be used for hardware debugging as well.
ALT 5: The useful pins here are the second serial port data and handshaking lines. The PWM lines are exactly the same PWM lines that are switches to GPIO 12 and 13 under ALT 0, only this time they’re switched to GPIO 20 and 21. There are also two of the general-purpose clock lines along with another copy of the ARM JTAG signals.