Skip to main content

Chapter 19 General Purpose Input/Output (GPIO) Device

I suggest reviewing Section 2.17 before reading this chapter. That section provides an introduction to accessing the GPIO in C, which is a good way to test your wiring before using assembly language.

The Raspberry Pi's GPIO device has a number of pins that can be switched on or off to provide \(3.5\) volts at a low current. This is sufficient to power things like LEDs, so you can use the GPIO to create your own experiments. In this chapter, we will learn how to switch the pins on and off in assembly language.

The GPIO has 54 general-purpose I/O pins, which are controlled by 41 32-bit registers. The function of each pin is selected through six of these registers, GPFSEL0GPFSEL5. Three bits are used to select the function of a GPIO pin, so each 32-bit register selects the function of ten pins, with two unused bits. We will consider only the first three registers.

I recommend downloading a copy of the Broadcom BCM2835 SoC datasheet[6] for reference while reading this chapter. It is not easy to read the datasheet, but I will use the same terminology. By going back and forth between this explanation and the datasheet, you should be able to figure out how to use the datasheet.