The Serial Peripheral Interface (SPI) module is a full-duplex synchronous-serial interface useful for communicating with other peripherals or microcontrollers in Master/Slave relationships and it can transfer data over short distances at high speeds. The peripheral devices may be serial EEPROMs, shift registers, display drivers, analog-to-digital converters, etc. The SPI module is compatible with Motorola’s SPI and Sheltered Instruction Observation Protocol (SIOP) interfaces.
During data transfer, devices can work either in Master or in Slave mode. The source of synchronization is the system clock, which is generated by the Master. The SPI module allows one or more Slave devices to be connected to a single Master device via the same bus.
The SPI serial interface consists of four pins, which are further sub-divided into data and control lines:
Data Lines:
- MOSI – Master Output, Slave Input
- MISO – Master Input, Slave Output
Control Lines:
- SCLK – Serial Clock
- /SS – Slave Select (no addressing)
The SPI module can be configured to operate using two, three, or four pins. In the 3-pin mode, the Slave Select line is not used. In the 2-pin mode, both the MOSI and /SS lines are not used.
Different types of SPIs are available on Microchip microcontrollers. Some have an internal buffer mechanism and some do not. The buffer depth varies across part families. The SPI driver abstracts out these differences and provides a unified model for data transfer across the different types of SPIs available.
Both transmitter and receiver provide a buffer in the driver which transmits and receives data to/from the hardware. The SPI driver provides a set of interfaces to perform the read and the write.