The Serial Peripheral Interface (SPI) module is a full-duplex synchronous-serial interface useful for communicating with other peripherals or microcontrollers in master/slave relationship 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:
- MOSI – Master Data Output, Slave Data Input
- MISO – Master Data Input, Slave Data Output
- 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 different types of SPIs available.
Both transmitter and receiver provides 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.