SPI protocol

The I2C bus interface is used for low-speed devices only. If you want to communicate with faster devices like LCD/LED display units, SD cards, Ethernet modules, then you need to use a faster bus on BeagleBone called the Serial Peripheral Interface (SPI). It provides high data rates in MB/s. Many sensors, DAC, Wi-Fi boards, and microcontroller boards support the SPI protocol. This protocol was developed by Motorola. It is popular in embedded systems.

SPI is a synchronous serial 4-wire protocol. Multiple devices can be connected to a single bus. So, it is a master-slave bus. One line is used to synchronize the clock signal (SCK/SCLK/CLK). The master provides the clock signal to all slaves. Two lines of MOSI and MISO are used to exchange data. MOSI carries data from the master to slave. MISO carries data from the slave to the master. So, SPI is a full duplex communication. MOSI and MISO lines are shared among all slave devices. One line is Chip Select (CS). It is also called Chip Enable (CE). The CS line is not shared. There is a separate line for each master-slave CS connection. So, the master needs as many CS pins as there are slaves to be connected. If not, regular GPIO pins can be used as a CS pin. It is active low which means if it is made LOW, that slave can communicate with the master. The master selects one slave among many on the bus for communication by changing the value on the CS pin. Once selected, communication happens only between that slave and master. The SPI protocol does not specify speed, flow control or any communication details. Different vendors expect different parameters. This gives protocol flexibility to manufacturers. SPI has the advantage of speed over I2C and UART. SPI speed is often more than 10 MBit/s.

The major disadvantage of SPI is—as slave devices on a bus increase, the number of connections increase. It becomes difficult to connect multiple devices. Also, there is no way to detect devices on a bus like I2C has. SPI works over short distances only compared with some UART standards. Some devices like a webcam need even more speed for communication. They can be interfaced with the USB port on BeagleBone.

BeagleBone has two SPI bus channels – SPI0 and SPI1. BeagleBone Black uses some pins of SPI1 for HDMI connection. So, you need to disable HDMI if you want to use the SPI1 bus. Refer to the following diagram to get information about SPI pins available on the BeagleBone:

SPI protocol

Let's write a program to interface the Nokia 5110 graphic LCD display using the SPI0 bus on BeagleBone. This was part of the Nokia 5110 handset. But it is still widely available in the embedded market. It uses a Philips PCD8544 controller chip inside. It can drive a black and white graphic display of 48x84 pixels. It has all SPI pins except a MISO pin as it is an output-only device. There are additional pins like Reset (RST/RES), LED control, and data/command pin (DC). The MOSI pin is sometimes labelled as DIN or SDIN:

SPI protocol
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.223.10