SlideShare a Scribd company logo
Serial Peripheral Interface
By:- Rishu
Master Slave
SCLK
MOSI
MISO
SS
Index
 Introduction
 Overview
 Communication
 Advantages
 Disadvantages
 Applications
Introduction
 Communication Protocol Developed By Motorola
 Four Wire Protocol
 Serial Interface
 Master-Slave Approach
 Synchronous- Data clocked with Clock Signal
 Data Rate-10mbps
 Full Duplex Protocol
 Low power than I2C (no need of Pull ups)
 Supports Single master and multiple slaves
 No hardware slave acknowledgement
Overview
 SPI stands for Serial Peripheral Interface
 Used for moving data simply and quickly from one device to another
 Used to communicate across small distances
 Master-Slave(Multiple Slaves, Single Master)
 Serial Interface
 Synchronous
 Data Exchange
Continue…
 SPI is a Master-Slave protocol
 The Master device controls the clock (SCK)
 No data is transferred unless a clock signal is present
 All slaves are controlled by the master clock
 The slave devices may not manipulate the clock
 Master Set Slave Select low
 Master Generates Clock
 Shift registers shift in and out data
Master Slave
SCLK
MOSI
MISO
SS
Continue…
 Simple SPI Protocol Specifies 4 Signal Wires
 Master Out Slave In (MOSI)
 Master In Slave Out (MISO)
 Serial Clock (SCLK)
 Slave Select (SS)
 MOSI – Carries data out of Master to Slave
 MISO – Carries data from Slave to Master (Both signals happen for every transmission)
 SS – Unique line to select a slave
 SCLK – Master produced clock to synchronize data transfer MOSI
Master Slave
SCLK
MOSI
MISO
SS
Continue…
 SPI is a Synchronous protocol
 The data is clocked along with a clock signal(SCK)
 The clock signal controls when data is changed and when it should be read
 Since SPI is synchronous, the clock rate can vary, unlike RS-232 style communications
Continue…
 SPI is a Data Exchange protocol
 As data is being clocked out, new data is clocked in
 Data is exchanged - no device can just be a transmitter only or receiver only
 the master controls the exchange by manipulating the clock line (SCK)
 Often a signal controls when a device is accessed - this is the CS or SS signal
 CS or SS signal is known as “Chip Select” or “Slave Select” and is frequently an active-low signal.
 Data is only output during the rising or falling edge of SCK
 Data is latched during the opposite edge of SCK
 The opposite edge is used to ensure data is valid at the time of reading
Fig.1 : Two SPI Modules connected in a Master-Slave
Configuration
 Master shifts out data to Slave, and shift in data from Slave
Serial Peripheral Interface(SPI)
 Data is shifted out of the master's MOSI pin and in its MISO pin.
 Data transfer is initiated by simply writing data to the SPI data register.
 All data movement is coordinated by SCK.
 Slave select may or may not be used depending on interfacing device.
 To get input data only you send “junk” data to SPDR to start the clock.
Single Master and Single Slave
Master Slave
SCLK
MOSI
MISO
SS
 Master
• Initiates the Connection
• Controls SCLK and Data transfer
 Slave
• Transmits Data
• Receives Data
Single Master and Multiple independent Slave
Master
SCLK
MOSI
MISO
SS1
SS2
SCLK
MOSI
MISO
SS
SCLK
MOSI
MISO
SS
Master and multiple daisy-chained slaves
How Do They Communicate
 Communication Initiated by Master only
 Master Configures the clock – Frequency less than equal to maximum frequency Slave
Support
 Master Selects Slave – By Pulling chip select(SS) of particular Slave-peripheral to Low State
Data Transmission Mode
SPI Mode CPOL CPHA Shift SCK
Edge
Capture SCK
Edge
0 0 0 Falling Raising
1 0 1 Raising Falling
2 1 0 Raising Falling
3 1 1 Falling Raising
Table : SPI Mode Configuration
SPI Transfer format with CPHA = 0
SPI Transfer format with CPHA = 1
Steps for Master Mode
 Set SPCCR (Clock Counter Register) with appropriate clock frequency
 Set SPCR (Control Register) to desired settings
 Write the data into SPDR (Data Register) of SPI
 Monitor SPIF bit of SPCR register, until it sets to 1(SPIF = 1 means data transfer is complete ).
 Read SPSR (Status Register), this will clear SPIF bit
 Read SPDR (Data Register), reading data register will return data sent by the slave during last
transfer.
Steps for Slave Mode
 Clock will be decided by Master
 Set SPCR (Control Register) to desired settings
 Write dummy data into SPDR (Data Register), so that SPI control block will generate Clock.
 Monitor SPIF bit of SPCR register, until it sets to 1
 Read SPSR (Status Register), this will clear SPIF bit
 Read SPDR (Data Register), reading data register will return data sent by the slave during last
transfer.
SPI Clock Counter Register (SPCCR)
 The SPCCR is used to set data transfer rate (SPI Frequency) It is 8 bit register, and the value
entered in this register is used to calculate frequency
SPI data rate = (PCLK / SPCCR value)
The value entered must be even value, thus LSB must be 0.The value should be greater
than 8.So maximum frequency is 1.875 MHz(PCLK = 15MHz).
SPI Control Register (SPCR)
SPIE SPE LSBF MSTR CPOL CPHA SPR1 SPR0
Bit 7 6 5 4 3 2 1 0
Read/Write
Initial Value
R/W R/W R/W R/W R/W R/W R/W R/W
0 0 0 0 0 0 0 0
SPCR
SPI Control Register (SPCR)
Bit 0&1: SPR0& SPR1
SPI2X SPR1 SPR0 SCLK
0 0 0 fosc/4
0 0 1 fosc/16
0 1 0 fosc/64
0 1 1 fosc/128
1 0 0 fosc/2
1 0 1 fosc/8
1 1 0 fosc/32
1 1 1 fosc/64
In SPSR Clock Rate
SPI Control Register (SPCR)
Bit 2: CPHA
CPHA stands for Clock Phase Control, and plays an important role in deciding the
relation between sampling of data and clock pulse
CPHA = 0 ; data is sampled on first clock edge
CPHA = 1 ; data is sampled on the second rising edge
•The important thing to be considered here is CPHA should be 0 when LPC2148 is used
as a SPI Master.
•It is mentioned in the User Manual of LPC2148 that SSEL signal is inactive during the
data transfer when CPHA is 0, but when CPHA is 1 the SSEL signal becomes active and
immediately transforms itself into slave.
•This results into a Mode Fault and data transfer terminates.
•In this case MODF bit of Status Register will set to 1.
SPI Control Register (SPCR)
Bit 3 : CPOL
•CPOL stands for Clock Polarity Control
•The bit decides the polarity of SPI clock, when set to 1 clock is active low. In that case
first clock will start with negative going pulse
•when set to 0 the clock is active high meaning that the clock will start with positive
going edge
CPOL = 0
CPOL = 1
SPI Control Register (SPCR)
Bit 4 : MSTR
The bit is used to configure SPI block in Master/Slave Mode
MSTR = 0 Slave Mode
MSTR = 1 Master Mode
Bit 5 : DORD or LSBF
The bit decides the direction of bit transfer
LSBF = 0 MSB is transferred first
LSBF = 1 LSB is transferred first
SPI Control Register (SPCR)
Bit 6 : SPE
•The bit is used to enable SPI Interface
SPE = 0 disable SPI Interface
SPE = 1 enable SPI Interface
•It is an interrupt Enable bit,
SPIE = 0 Interrupt are disabled
SPIE = 1 Interrupts are enabled and will occur when SPI/ WCOL bit is set.
Bit 7 : SPIE
SPI Status Register (SPSR)
Bit 0 : SPI2X
Bit 6 : WCOL
•The bit is used to set double clock rate in master mode
SPI2X = 0 normal clock rate
SPI2X = 1 double clock rate
•The bit is used for write collision
WCOL is set if SPDR is written during a receive transfer
SPI Status Register (SPSR)
Bit 7 : SPIF
•The bit is used for interrupt flag
SPIF bit is set when serial transfer is complete.
SPIF WCOL - - - - - SPI2X SPSR
Bit 7 6 5 4 3 2 1 0
Read/Write
Initial Value
R R R R R R R R/W
0 0 0 0 0 0 0 0
SPI Data Register (SPDR)
 It is 16 bit register used in data transfer, the data length is selectable (8 –16bits).
 The data length can be configured by using bit 2 (BitEnable) and bits 11:8 of control register.
 There is no buffer between the data register and the internal shift register.
 A write to the data register goes directly into the internal shift register.
 Therefore, data should only be written to this register when a transmit is not currently in
progress. Otherwise a Collision Error may occur.
 Read data is buffered. When a transfer is complete, the receive data is transferred to a single
byte data buffer, where it is later read.
MSB - - - - - - LSB SPDR
Bit 7 6 5 4 3 2 1 0
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
X X X X X X X X
Advantages
 Full Duplex Communication
 Higher Throughput than I2C
 Not Limited to 8 bit words in case of bit transferring
 Arbitrary choice of message size, content and Purpose
 Low Power
 Fast and easy
 Fast for point-to-point connections
 Easily allows streaming/Constant data inflow
 No addressing/Simple to implement
 Everyone supports it
Disadvantages
 Requires more pins than I2C
 No hardware flow control
 No Slave Acknowledgement ability
 No inherent arbitration
 Multi Master Difficult to Implement
 SS makes multiple slaves very complicated
 Short Distance
SPI Peripherals
 Converters (ADC, DAC)
 Memories (EEPROM, RAM’s, Flash)
 Sensors (Temperature, Humidity, Pressure)
 Real Time Clocks
 Misc.- Potentiometers, LCD controllers, UART’s, USB controller, CAN controller, amplifiers
Some Important Facts
 A read or write of the SPI data register is required in order to clear the SPIF status
bit.
 The prime function of SPSR register is to indicate the completion of data transfer
between two devices. The remaining bits of SPSR register.
 When CPHA = 0, the SSEL signal will always go inactive between data transfers.
This is not guaranteed when CPHA = 1 (the signal can remain active).
Thank You !!!

More Related Content

What's hot

Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
Chirag Parikh
 
I2C
I2CI2C
SPI.ppt
SPI.pptSPI.ppt
SPI.ppt
LingaReddyC
 
Uart
UartUart
AMBA 3 APB Protocol
AMBA 3 APB ProtocolAMBA 3 APB Protocol
AMBA 3 APB Protocol
Swetha GSM
 
Advance Peripheral Bus
Advance Peripheral Bus Advance Peripheral Bus
Advance Peripheral Bus
SIVA NAGENDRA REDDY
 
I2C
I2CI2C
I2C introduction
I2C introductionI2C introduction
I2C introduction
SUNODH GARLAPATI
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
Akhil Srivastava
 
Introduction about APB Protocol
Introduction about APB ProtocolIntroduction about APB Protocol
Introduction about APB Protocol
Pushpa Yakkala
 
Spi master core verification
Spi master core verificationSpi master core verification
Spi master core verificationMaulik Suthar
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)Varun Mahajan
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
Aditya Porwal
 
I2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication ProtocolI2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication Protocol
Ankur Soni
 
Slow peripheral interfaces (i2 c spi uart)
Slow peripheral interfaces (i2 c  spi uart)Slow peripheral interfaces (i2 c  spi uart)
Slow peripheral interfaces (i2 c spi uart)
PREMAL GAJJAR
 
Axi
AxiAxi
The I2C Interface
The I2C InterfaceThe I2C Interface
The I2C Interface
Corrado Santoro
 
Axi protocol
Axi protocolAxi protocol
Axi protocol
Azad Mishra
 
AXI Protocol.pptx
AXI Protocol.pptxAXI Protocol.pptx
AXI Protocol.pptx
Yazan Yousef
 

What's hot (20)

Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
I2C
I2CI2C
I2C
 
UART
UARTUART
UART
 
SPI.ppt
SPI.pptSPI.ppt
SPI.ppt
 
Uart
UartUart
Uart
 
AMBA 3 APB Protocol
AMBA 3 APB ProtocolAMBA 3 APB Protocol
AMBA 3 APB Protocol
 
Advance Peripheral Bus
Advance Peripheral Bus Advance Peripheral Bus
Advance Peripheral Bus
 
I2C
I2CI2C
I2C
 
I2C introduction
I2C introductionI2C introduction
I2C introduction
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
 
Introduction about APB Protocol
Introduction about APB ProtocolIntroduction about APB Protocol
Introduction about APB Protocol
 
Spi master core verification
Spi master core verificationSpi master core verification
Spi master core verification
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
 
I2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication ProtocolI2c protocol - Inter–Integrated Circuit Communication Protocol
I2c protocol - Inter–Integrated Circuit Communication Protocol
 
Slow peripheral interfaces (i2 c spi uart)
Slow peripheral interfaces (i2 c  spi uart)Slow peripheral interfaces (i2 c  spi uart)
Slow peripheral interfaces (i2 c spi uart)
 
Axi
AxiAxi
Axi
 
The I2C Interface
The I2C InterfaceThe I2C Interface
The I2C Interface
 
Axi protocol
Axi protocolAxi protocol
Axi protocol
 
AXI Protocol.pptx
AXI Protocol.pptxAXI Protocol.pptx
AXI Protocol.pptx
 

Viewers also liked

Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
Adair Dingle
 
Arm developement
Arm developementArm developement
Arm developement
hirokiht
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
Abhijeet kapse
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
Janki Shah
 
Arm processor
Arm processorArm processor
Arm processor
SHREEHARI WADAWADAGI
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
adil raja
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
sato262
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
Sonali Parab
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
Emertxe Information Technologies Pvt Ltd
 
Embedded C
Embedded CEmbedded C
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
Ronak Chhajed
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
Emertxe Information Technologies Pvt Ltd
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
Mohamed Abdallah
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
Abhijeet kapse
 
Code Optimization
Code OptimizationCode Optimization
Code Optimizationguest9f8315
 
Iot
IotIot

Viewers also liked (16)

Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
 
Arm developement
Arm developementArm developement
Arm developement
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
 
Arm processor
Arm processorArm processor
Arm processor
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Iot
IotIot
Iot
 

Similar to Serial Peripheral Interface

Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
Aarav Soni
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
IJERD Editor
 
UNI T 6- SPI_I2C_Lecture8.pptx
UNI                    T 6- SPI_I2C_Lecture8.pptxUNI                    T 6- SPI_I2C_Lecture8.pptx
UNI T 6- SPI_I2C_Lecture8.pptx
naveen088888
 
I2 c and mpu6050 basics
I2 c and mpu6050 basicsI2 c and mpu6050 basics
I2 c and mpu6050 basics
ironstein1994
 
Master synchronous serial port (mssp)
Master synchronous serial port (mssp)Master synchronous serial port (mssp)
Master synchronous serial port (mssp)
babak danyal
 
Introduction to embedded systems
Introduction to embedded systemsIntroduction to embedded systems
Introduction to embedded systems
Игорь Медведев
 
Assembler4
Assembler4Assembler4
Assembler4
Omar Sanchez
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systems
Raghunath reddy
 
spi-180501092933-converted.pptx
spi-180501092933-converted.pptxspi-180501092933-converted.pptx
spi-180501092933-converted.pptx
sauryakumar3
 
10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt
ABDULRHMANMohammad3
 
Designing of fifo and serial peripheral interface protocol using Verilog HDL
Designing of fifo and serial peripheral interface protocol using Verilog HDLDesigning of fifo and serial peripheral interface protocol using Verilog HDL
Designing of fifo and serial peripheral interface protocol using Verilog HDL
Jay Baxi
 
Part-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentPart-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver development
FastBit Embedded Brain Academy
 
LPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptxLPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptx
dhanashribiradar2
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
RAMPRAKASHT1
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp port
Teju Kotti
 
I2C PRESENTATION.PPT
I2C PRESENTATION.PPTI2C PRESENTATION.PPT
I2C PRESENTATION.PPT
venkatesh405785
 
8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx
maheswariM7
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Mohamed Abdallah
 

Similar to Serial Peripheral Interface (20)

Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
 
Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)Welcome to International Journal of Engineering Research and Development (IJERD)
Welcome to International Journal of Engineering Research and Development (IJERD)
 
UNI T 6- SPI_I2C_Lecture8.pptx
UNI                    T 6- SPI_I2C_Lecture8.pptxUNI                    T 6- SPI_I2C_Lecture8.pptx
UNI T 6- SPI_I2C_Lecture8.pptx
 
I2 c and mpu6050 basics
I2 c and mpu6050 basicsI2 c and mpu6050 basics
I2 c and mpu6050 basics
 
Master synchronous serial port (mssp)
Master synchronous serial port (mssp)Master synchronous serial port (mssp)
Master synchronous serial port (mssp)
 
Introduction to embedded systems
Introduction to embedded systemsIntroduction to embedded systems
Introduction to embedded systems
 
Assembler4
Assembler4Assembler4
Assembler4
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systems
 
spi-180501092933-converted.pptx
spi-180501092933-converted.pptxspi-180501092933-converted.pptx
spi-180501092933-converted.pptx
 
10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt
 
Designing of fifo and serial peripheral interface protocol using Verilog HDL
Designing of fifo and serial peripheral interface protocol using Verilog HDLDesigning of fifo and serial peripheral interface protocol using Verilog HDL
Designing of fifo and serial peripheral interface protocol using Verilog HDL
 
Part-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentPart-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver development
 
LPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptxLPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptx
 
Spi (1)
Spi (1)Spi (1)
Spi (1)
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp port
 
I2C PRESENTATION.PPT
I2C PRESENTATION.PPTI2C PRESENTATION.PPT
I2C PRESENTATION.PPT
 
8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
 
Lpc2148 i2c
Lpc2148 i2cLpc2148 i2c
Lpc2148 i2c
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 

Serial Peripheral Interface

  • 1. Serial Peripheral Interface By:- Rishu Master Slave SCLK MOSI MISO SS
  • 2. Index  Introduction  Overview  Communication  Advantages  Disadvantages  Applications
  • 3. Introduction  Communication Protocol Developed By Motorola  Four Wire Protocol  Serial Interface  Master-Slave Approach  Synchronous- Data clocked with Clock Signal  Data Rate-10mbps  Full Duplex Protocol  Low power than I2C (no need of Pull ups)  Supports Single master and multiple slaves  No hardware slave acknowledgement
  • 4. Overview  SPI stands for Serial Peripheral Interface  Used for moving data simply and quickly from one device to another  Used to communicate across small distances  Master-Slave(Multiple Slaves, Single Master)  Serial Interface  Synchronous  Data Exchange
  • 5. Continue…  SPI is a Master-Slave protocol  The Master device controls the clock (SCK)  No data is transferred unless a clock signal is present  All slaves are controlled by the master clock  The slave devices may not manipulate the clock  Master Set Slave Select low  Master Generates Clock  Shift registers shift in and out data Master Slave SCLK MOSI MISO SS
  • 6. Continue…  Simple SPI Protocol Specifies 4 Signal Wires  Master Out Slave In (MOSI)  Master In Slave Out (MISO)  Serial Clock (SCLK)  Slave Select (SS)  MOSI – Carries data out of Master to Slave  MISO – Carries data from Slave to Master (Both signals happen for every transmission)  SS – Unique line to select a slave  SCLK – Master produced clock to synchronize data transfer MOSI Master Slave SCLK MOSI MISO SS
  • 7. Continue…  SPI is a Synchronous protocol  The data is clocked along with a clock signal(SCK)  The clock signal controls when data is changed and when it should be read  Since SPI is synchronous, the clock rate can vary, unlike RS-232 style communications
  • 8. Continue…  SPI is a Data Exchange protocol  As data is being clocked out, new data is clocked in  Data is exchanged - no device can just be a transmitter only or receiver only  the master controls the exchange by manipulating the clock line (SCK)  Often a signal controls when a device is accessed - this is the CS or SS signal  CS or SS signal is known as “Chip Select” or “Slave Select” and is frequently an active-low signal.  Data is only output during the rising or falling edge of SCK  Data is latched during the opposite edge of SCK  The opposite edge is used to ensure data is valid at the time of reading
  • 9. Fig.1 : Two SPI Modules connected in a Master-Slave Configuration  Master shifts out data to Slave, and shift in data from Slave
  • 10. Serial Peripheral Interface(SPI)  Data is shifted out of the master's MOSI pin and in its MISO pin.  Data transfer is initiated by simply writing data to the SPI data register.  All data movement is coordinated by SCK.  Slave select may or may not be used depending on interfacing device.  To get input data only you send “junk” data to SPDR to start the clock.
  • 11. Single Master and Single Slave Master Slave SCLK MOSI MISO SS  Master • Initiates the Connection • Controls SCLK and Data transfer  Slave • Transmits Data • Receives Data
  • 12. Single Master and Multiple independent Slave Master SCLK MOSI MISO SS1 SS2 SCLK MOSI MISO SS SCLK MOSI MISO SS
  • 13. Master and multiple daisy-chained slaves
  • 14. How Do They Communicate  Communication Initiated by Master only  Master Configures the clock – Frequency less than equal to maximum frequency Slave Support  Master Selects Slave – By Pulling chip select(SS) of particular Slave-peripheral to Low State
  • 15. Data Transmission Mode SPI Mode CPOL CPHA Shift SCK Edge Capture SCK Edge 0 0 0 Falling Raising 1 0 1 Raising Falling 2 1 0 Raising Falling 3 1 1 Falling Raising Table : SPI Mode Configuration
  • 16. SPI Transfer format with CPHA = 0
  • 17. SPI Transfer format with CPHA = 1
  • 18.
  • 19. Steps for Master Mode  Set SPCCR (Clock Counter Register) with appropriate clock frequency  Set SPCR (Control Register) to desired settings  Write the data into SPDR (Data Register) of SPI  Monitor SPIF bit of SPCR register, until it sets to 1(SPIF = 1 means data transfer is complete ).  Read SPSR (Status Register), this will clear SPIF bit  Read SPDR (Data Register), reading data register will return data sent by the slave during last transfer.
  • 20. Steps for Slave Mode  Clock will be decided by Master  Set SPCR (Control Register) to desired settings  Write dummy data into SPDR (Data Register), so that SPI control block will generate Clock.  Monitor SPIF bit of SPCR register, until it sets to 1  Read SPSR (Status Register), this will clear SPIF bit  Read SPDR (Data Register), reading data register will return data sent by the slave during last transfer.
  • 21.
  • 22. SPI Clock Counter Register (SPCCR)  The SPCCR is used to set data transfer rate (SPI Frequency) It is 8 bit register, and the value entered in this register is used to calculate frequency SPI data rate = (PCLK / SPCCR value) The value entered must be even value, thus LSB must be 0.The value should be greater than 8.So maximum frequency is 1.875 MHz(PCLK = 15MHz). SPI Control Register (SPCR) SPIE SPE LSBF MSTR CPOL CPHA SPR1 SPR0 Bit 7 6 5 4 3 2 1 0 Read/Write Initial Value R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 SPCR
  • 23. SPI Control Register (SPCR) Bit 0&1: SPR0& SPR1 SPI2X SPR1 SPR0 SCLK 0 0 0 fosc/4 0 0 1 fosc/16 0 1 0 fosc/64 0 1 1 fosc/128 1 0 0 fosc/2 1 0 1 fosc/8 1 1 0 fosc/32 1 1 1 fosc/64 In SPSR Clock Rate
  • 24. SPI Control Register (SPCR) Bit 2: CPHA CPHA stands for Clock Phase Control, and plays an important role in deciding the relation between sampling of data and clock pulse CPHA = 0 ; data is sampled on first clock edge CPHA = 1 ; data is sampled on the second rising edge •The important thing to be considered here is CPHA should be 0 when LPC2148 is used as a SPI Master. •It is mentioned in the User Manual of LPC2148 that SSEL signal is inactive during the data transfer when CPHA is 0, but when CPHA is 1 the SSEL signal becomes active and immediately transforms itself into slave. •This results into a Mode Fault and data transfer terminates. •In this case MODF bit of Status Register will set to 1.
  • 25. SPI Control Register (SPCR) Bit 3 : CPOL •CPOL stands for Clock Polarity Control •The bit decides the polarity of SPI clock, when set to 1 clock is active low. In that case first clock will start with negative going pulse •when set to 0 the clock is active high meaning that the clock will start with positive going edge CPOL = 0 CPOL = 1
  • 26. SPI Control Register (SPCR) Bit 4 : MSTR The bit is used to configure SPI block in Master/Slave Mode MSTR = 0 Slave Mode MSTR = 1 Master Mode Bit 5 : DORD or LSBF The bit decides the direction of bit transfer LSBF = 0 MSB is transferred first LSBF = 1 LSB is transferred first
  • 27. SPI Control Register (SPCR) Bit 6 : SPE •The bit is used to enable SPI Interface SPE = 0 disable SPI Interface SPE = 1 enable SPI Interface •It is an interrupt Enable bit, SPIE = 0 Interrupt are disabled SPIE = 1 Interrupts are enabled and will occur when SPI/ WCOL bit is set. Bit 7 : SPIE
  • 28. SPI Status Register (SPSR) Bit 0 : SPI2X Bit 6 : WCOL •The bit is used to set double clock rate in master mode SPI2X = 0 normal clock rate SPI2X = 1 double clock rate •The bit is used for write collision WCOL is set if SPDR is written during a receive transfer
  • 29. SPI Status Register (SPSR) Bit 7 : SPIF •The bit is used for interrupt flag SPIF bit is set when serial transfer is complete. SPIF WCOL - - - - - SPI2X SPSR Bit 7 6 5 4 3 2 1 0 Read/Write Initial Value R R R R R R R R/W 0 0 0 0 0 0 0 0
  • 30. SPI Data Register (SPDR)  It is 16 bit register used in data transfer, the data length is selectable (8 –16bits).  The data length can be configured by using bit 2 (BitEnable) and bits 11:8 of control register.  There is no buffer between the data register and the internal shift register.  A write to the data register goes directly into the internal shift register.  Therefore, data should only be written to this register when a transmit is not currently in progress. Otherwise a Collision Error may occur.  Read data is buffered. When a transfer is complete, the receive data is transferred to a single byte data buffer, where it is later read. MSB - - - - - - LSB SPDR Bit 7 6 5 4 3 2 1 0 Read/Write R/W R/W R/W R/W R/W R/W R/W R/W X X X X X X X X
  • 31. Advantages  Full Duplex Communication  Higher Throughput than I2C  Not Limited to 8 bit words in case of bit transferring  Arbitrary choice of message size, content and Purpose  Low Power  Fast and easy  Fast for point-to-point connections  Easily allows streaming/Constant data inflow  No addressing/Simple to implement  Everyone supports it
  • 32. Disadvantages  Requires more pins than I2C  No hardware flow control  No Slave Acknowledgement ability  No inherent arbitration  Multi Master Difficult to Implement  SS makes multiple slaves very complicated  Short Distance
  • 33. SPI Peripherals  Converters (ADC, DAC)  Memories (EEPROM, RAM’s, Flash)  Sensors (Temperature, Humidity, Pressure)  Real Time Clocks  Misc.- Potentiometers, LCD controllers, UART’s, USB controller, CAN controller, amplifiers
  • 34. Some Important Facts  A read or write of the SPI data register is required in order to clear the SPIF status bit.  The prime function of SPSR register is to indicate the completion of data transfer between two devices. The remaining bits of SPSR register.  When CPHA = 0, the SSEL signal will always go inactive between data transfers. This is not guaranteed when CPHA = 1 (the signal can remain active).