SPI Communication
SPI Communication
SPI stands for Serial Peripheral Interface works on Master-slave concept.It is a synchronous serial
communication used for short distance communication.
In multi-slave communication, Master will select a slave to establish communication through slave select (SS)
line or chip select line(CS) by pulling it down.
The diagram shows the Interface and Direction between Master and Slave.
Master should select Slave device through Slave select line by making it low—-SS
Master device con gures the SPI peripheral clock supported by Slave also.——SCLK
Data availability on Data out(MOSI) and Data in(MISO) line controlled by the master generated Clock
Pulse(SCLK).
Master generated clock pulse polarity(CPOL) and phase(CPHA) decides the data drive on the data line. see the
below image.
CPHA: Determines the timing of the data bits relative to the clock pulse.
HARDWARE CONFIGURATION
For SPI Communication you need to con gure following peripheral in MCU.
1. Port Pins
2. MCU clock
3. SPI Peripheral Engine
Port Pins:
Direction and alternate function need to con gure for the Port Pins those are used by SPI module. Suppose
Following GPIO Pins are xed by the manufacturer for SPI communication as an alternate function. See the
following table –
MCU Clock:
We need to Con gure the MCU clock and peripheral Clock to x the SCLK frequency.
We need to con gure one of them to work as a Master or Slave through the API as per the
Microcontroller Speci c User Manual.
In below gure, three slave select lines(Channels) are present and each one is connected with different-2
slaves.
Master will take control of this slave select line and master can select or deselect the slave through SS line.
1. Write Command
2. Address
3. Data to write
slave select line must be low until above three data does not transfer completely.
let ,
1. write command=0x12
2. Address =0x00000000
3. Data ={0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}
1. Read Command
2. Address
slave select line must be low until above three data does not transfer completely.
let ,
1. Read command=0x13
2. Address =0x00000000