The Raspberry Pi can be used for just about anything. It’s safe to say that the Pi and similar single board computers are becoming ubiquitous.
When you start experimenting with GPIO pins on your Raspberry Pi, things get even more interesting. We’ve already covered what all of these pins do, so now let’s take a look at how to enable the SPI and I2C protocols on your Pi and why you might want to.
What is SPI on Raspberry Pi?
Before diving in, let’s take a quick look at what these two protocols do.
SPI (or Serial Peripheral Interface) allows a microcontroller like the Pi to communicate with more than 100 peripheral components at the same time. The microcontroller acts as a «master» for all «slave» components and can communicate with them at high speed. This diagram describes a simple SPI connection:
If you are reading about SPI for the first time, this may seem intimidating, but keep up the good work! SCLK is the clock frequency set by the master, which determines the rate at which information is distributed between devices.
In each cycle (or «tick») of the clock, both master and slave send and receive one bit of information. This requires contacts. MOSI (Master Out Slave In) and MISO (Master In Slave Out).
Conclusion SS or Slave Select (labeled CE0 or CE1 on the Pi) is used to tell the slave whether to communicate with the master or not — at any given time. In most cases, each slave requires its own SS pin, but may share SCLK, MOSI, and MISO pins.
Some devices can be «daisy-chained» to share the SS pin, with a total of four pins used, plus two for power and ground. SPI is known for being incredibly fast and is commonly used in shift registers or ADCs (analogue-to-digital converters) to transfer data between devices.
There is a simple tutorial for SPI on Advanced Startup YouTube channel explaining the protocol further:
How to enable SPI on Raspberry Pi
To enable SPI on Raspberry Pi, open raspi-config from a terminal by typing:
Go to Interface Options and in the next menu choose P4 SPI Enable/disable automatic loading of the SPI kernel module . Select Yes in the request window. SPI is now enabled!
Also, you can enable SPI from file /boot/config.txt . Open a terminal window and type:
sudo nano /boot/config.txt
Find the line that says #dtparam=spi=on and remove the character # . Whichever way you enable SPI, reset the Pi and SPI.
What can you do with SPI on Raspberry Pi?
While there are hundreds of different projects that use many different SPI peripherals, programming your own RFID reader is a good starting project.