SlideShare a Scribd company logo
SPI Protocol in LPC2148
By- Dnyanesh P. Joshi
Instrumentation & Communication Unit
SPI Overview
SCK: Serial Clock, provided by Master
MOSI: Master Out Slave In
MISO: Master In Slave Out
SS: Slave Select
• SPI stands for Serial Peripheral Interface
• designed by Motorola
• four wire protocol
• Full Duplex protocol
• Low power than I2C (no need of Pull ups)
• Supports Single master and multiple slaves
• No hardware slave acknowledgement
Instrumentation & Communication Unit
Data Transfer Modes of LPC2148
It can be broadly divided into two categories
• Master Mode • Slave Mode
LPC2148
SPI
Slave
SCLK
MOSI
MISO
SSEL
SPI
Slave
SCLK
MOSI
MISO
SSEL
SPI
Slave
SCLK
MOSI
MISO
SSELLPC 2148
LPC 2148
LPC 2148
SCLK
MOSI
MISO
SS1
SS2
SS3
SPI
Master
Instrumentation & Communication Unit
Slave Select line is shown as
Input & not Output
MOSI is configured as Input when we are
using LPC2148 as SPI Slave
MOSI is configured as Output,
when we are using LPC2148 as SPI Master
Instrumentation & Communication Unit
• 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 Master 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.
Steps for Slave Mode
Instrumentation & Communication Unit
START
Set SPCCR
Set SPCR
Monitor SPIF bit
Write data
to SPDR
Is SPIF
set ?
Read SPSR
Read SPDR
END
No
Yes
SPI Initialization process
Writing data to Data Registers
Instrumentation & Communication Unit
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).
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.
Instrumentation & Communication Unit
SPCR (Control Register)
This bit can be used to select the data length for SPI protocol
The minimum data length is 8bits and maximum 16bits
When BitEnable = 0 , data length is fixed & considered to be 8bits
When BitEnable = 1 , data length depends upon the combinations of 11:8 bits of SPCR
For example, we are using SPI compatible 12 bit ADC
In this case, the ADC result will be of 12 bits
BitEnable = 1
Bits 11: 8 = 1100 (Combination for 12 bits)
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
Bit 3: CPHA
Bit 2: BitEnable
Instrumentation & Communication Unit
• 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.
• 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
Bit 4: CPOL
Instrumentation & Communication Unit
• The bit is used to configure SPI block in Master/Slave Mode
• MSTR = 0 Slave Mode
• MSTR = 1 Master Mode
Bit 5: MSTR
• The bit decides the direction of bit transfer
• LSBF = 0 MSB is transferred first
• LSBF = 1 LSB is transferred first
Bit 6: LSBF
• 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
Instrumentation & Communication Unit
When bit 2 of this register is 1, this field controls the number of bits per transfer:
1000 8 bits per transfer
1001 9 bits per transfer
1010 10 bits per transfer
1011 11 bits per transfer
1100 12 bits per transfer
1101 13 bits per transfer
1110 14 bits per transfer
1111 15 bits per transfer
0000 16 bits per transfer
Bit 11:8 BITS
Example: The target device is 12bit ADC, which is slave and LPC2148 is Master
Bit 0 1 2 3 4 5 6 7 8 9 10 11
- - 1 0 0 1 0 0 1 1 0 0
Control Register (SPCR)
Instrumentation & Communication Unit
Some Imp points…
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). (pg
169)
Instrumentation & Communication Unit
Thank You !!!
Instrumentation & Communication Unit

More Related Content

What's hot

axi protocol
axi protocolaxi protocol
axi protocol
Azad Mishra
 
I2C
I2CI2C
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
Techvilla
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
8251 USART
8251 USART8251 USART
8251 USART
ShivamSood22
 
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
Aarav Soni
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
Abhijeet kapse
 
8251 USART
8251 USART8251 USART
8251 USART
coolsdhanesh
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
Chirag Parikh
 
Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)
Emertxe Information Technologies Pvt Ltd
 
I2C BUS PROTOCOL
I2C BUS PROTOCOLI2C BUS PROTOCOL
I2C BUS PROTOCOL
Kashyap Mandaliya
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)Varun Mahajan
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
abhikalmegh
 
I2C introduction
I2C introductionI2C introduction
I2C introduction
SUNODH GARLAPATI
 
INTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORINTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSOR
Sagar Kuntumal
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
Aarav Soni
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
Anurag Tomar
 
I2C
I2CI2C

What's hot (20)

axi protocol
axi protocolaxi protocol
axi protocol
 
I2C
I2CI2C
I2C
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
8251 USART
8251 USART8251 USART
8251 USART
 
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
8251 USART
8251 USART8251 USART
8251 USART
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)
 
I2C BUS PROTOCOL
I2C BUS PROTOCOLI2C BUS PROTOCOL
I2C BUS PROTOCOL
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
 
I2C introduction
I2C introductionI2C introduction
I2C introduction
 
INTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORINTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSOR
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
I2C
I2CI2C
I2C
 
Interfacing 8255
Interfacing 8255Interfacing 8255
Interfacing 8255
 
UART
UARTUART
UART
 

Viewers also liked

Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148
sravannunna24
 
Serial Peripherical Interface (SPI)
Serial Peripherical Interface (SPI)Serial Peripherical Interface (SPI)
Serial Peripherical Interface (SPI)
OswST
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
Abhijeet kapse
 
Arm7 Interfacing examples
Arm7   Interfacing examples Arm7   Interfacing examples
Arm7 Interfacing examples
Dr.YNM
 
LPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLERLPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLER
sravannunna24
 
Interfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 MicrocontrollerInterfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 Microcontroller
Pantech ProLabs India Pvt Ltd
 
MONIKA SIYAL RESUME
MONIKA  SIYAL RESUMEMONIKA  SIYAL RESUME
MONIKA SIYAL RESUMEMonika siyal
 
Cyber crime
Cyber crimeCyber crime
Cyber crime
JASJIT SINGH
 
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Study on 32-bit Cortex - M3 Powered MCU: STM32F101Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Premier Farnell
 
Broadband networking through human body
Broadband networking through human bodyBroadband networking through human body
Broadband networking through human body
Mayank Garg
 
L T A Activities@IITB-Amool
L T A Activities@IITB-AmoolL T A Activities@IITB-Amool
L T A Activities@IITB-Amool
Amool Raina
 
Stellaris® 9000 Family of ARM® Cortex™-M3
Stellaris® 9000 Family of ARM® Cortex™-M3 Stellaris® 9000 Family of ARM® Cortex™-M3
Stellaris® 9000 Family of ARM® Cortex™-M3
Premier Farnell
 
The RoboCV Workshop
The RoboCV WorkshopThe RoboCV Workshop
The RoboCV Workshop
Utkarsh Sinha
 
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICsARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
Infineon4Engineers
 
Michaela
MichaelaMichaela
Arm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_modelArm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_model
Ganesh Naik
 
1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC
1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC 1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC
1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC
IEEE SSCS AlexSC
 
NEHA RESUME (1) (3)
NEHA RESUME (1) (3)NEHA RESUME (1) (3)
NEHA RESUME (1) (3)neha rathore
 

Viewers also liked (20)

Lpc2148 i2c
Lpc2148 i2cLpc2148 i2c
Lpc2148 i2c
 
Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148
 
Serial Peripherical Interface (SPI)
Serial Peripherical Interface (SPI)Serial Peripherical Interface (SPI)
Serial Peripherical Interface (SPI)
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
 
Arm7 Interfacing examples
Arm7   Interfacing examples Arm7   Interfacing examples
Arm7 Interfacing examples
 
LPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLERLPC 2148 ARM MICROCONTROLLER
LPC 2148 ARM MICROCONTROLLER
 
Interfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 MicrocontrollerInterfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 Microcontroller
 
MONIKA SIYAL RESUME
MONIKA  SIYAL RESUMEMONIKA  SIYAL RESUME
MONIKA SIYAL RESUME
 
7508 dcf ed01
7508 dcf ed017508 dcf ed01
7508 dcf ed01
 
Cyber crime
Cyber crimeCyber crime
Cyber crime
 
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Study on 32-bit Cortex - M3 Powered MCU: STM32F101Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
 
Broadband networking through human body
Broadband networking through human bodyBroadband networking through human body
Broadband networking through human body
 
L T A Activities@IITB-Amool
L T A Activities@IITB-AmoolL T A Activities@IITB-Amool
L T A Activities@IITB-Amool
 
Stellaris® 9000 Family of ARM® Cortex™-M3
Stellaris® 9000 Family of ARM® Cortex™-M3 Stellaris® 9000 Family of ARM® Cortex™-M3
Stellaris® 9000 Family of ARM® Cortex™-M3
 
The RoboCV Workshop
The RoboCV WorkshopThe RoboCV Workshop
The RoboCV Workshop
 
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICsARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
 
Michaela
MichaelaMichaela
Michaela
 
Arm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_modelArm cm3 architecture_and_programmer_model
Arm cm3 architecture_and_programmer_model
 
1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC
1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC 1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC
1: Interfacing using ARM Cortex M4 || IEEE SSCS AlexSC
 
NEHA RESUME (1) (3)
NEHA RESUME (1) (3)NEHA RESUME (1) (3)
NEHA RESUME (1) (3)
 

Similar to SPI Protocol in 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)
IJERD Editor
 
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD CoverterUniversal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Tejas Shetye
 
I2 c and mpu6050 basics
I2 c and mpu6050 basicsI2 c and mpu6050 basics
I2 c and mpu6050 basics
ironstein1994
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
Anbuselvi Mathivanan
 
LPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptxLPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptx
dhanashribiradar2
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcd
abhishek upadhyay
 
8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx
maheswariM7
 
PIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarPIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikar
GauravRaikar3
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
RAMPRAKASHT1
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdf
satyamsinha37
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
Chirag Lakhani
 
Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....
ANKUSH445845
 
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
 
10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt
ABDULRHMANMohammad3
 
Design and Fabrication of 4-bit processor
Design and Fabrication of  4-bit processorDesign and Fabrication of  4-bit processor
Design and Fabrication of 4-bit processor
Priyatham Bollimpalli
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
MemonaMemon1
 
Master synchronous serial port (mssp)
Master synchronous serial port (mssp)Master synchronous serial port (mssp)
Master synchronous serial port (mssp)
babak danyal
 
Presentation (1)-3.pptx
Presentation (1)-3.pptxPresentation (1)-3.pptx
Presentation (1)-3.pptx
RushikeshSawant37
 
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptxlec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
MadavanR1
 

Similar to SPI Protocol in LPC2148 (20)

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)
 
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD CoverterUniversal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
 
I2 c and mpu6050 basics
I2 c and mpu6050 basicsI2 c and mpu6050 basics
I2 c and mpu6050 basics
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
 
LPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptxLPC2148 SPI (Serial Peripheral Interface).pptx
LPC2148 SPI (Serial Peripheral Interface).pptx
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcd
 
Lab3
Lab3Lab3
Lab3
 
8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx
 
PIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarPIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikar
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdf
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
 
Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....
 
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
 
10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt
 
Design and Fabrication of 4-bit processor
Design and Fabrication of  4-bit processorDesign and Fabrication of  4-bit processor
Design and Fabrication of 4-bit processor
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
Master synchronous serial port (mssp)
Master synchronous serial port (mssp)Master synchronous serial port (mssp)
Master synchronous serial port (mssp)
 
Presentation (1)-3.pptx
Presentation (1)-3.pptxPresentation (1)-3.pptx
Presentation (1)-3.pptx
 
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptxlec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
lec3-8051microcontrollerarchitecture-230130044236-5c11a082.pptx
 

SPI Protocol in LPC2148

  • 1. SPI Protocol in LPC2148 By- Dnyanesh P. Joshi Instrumentation & Communication Unit
  • 2. SPI Overview SCK: Serial Clock, provided by Master MOSI: Master Out Slave In MISO: Master In Slave Out SS: Slave Select • SPI stands for Serial Peripheral Interface • designed by Motorola • four wire protocol • Full Duplex protocol • Low power than I2C (no need of Pull ups) • Supports Single master and multiple slaves • No hardware slave acknowledgement Instrumentation & Communication Unit
  • 3. Data Transfer Modes of LPC2148 It can be broadly divided into two categories • Master Mode • Slave Mode LPC2148 SPI Slave SCLK MOSI MISO SSEL SPI Slave SCLK MOSI MISO SSEL SPI Slave SCLK MOSI MISO SSELLPC 2148 LPC 2148 LPC 2148 SCLK MOSI MISO SS1 SS2 SS3 SPI Master Instrumentation & Communication Unit
  • 4. Slave Select line is shown as Input & not Output MOSI is configured as Input when we are using LPC2148 as SPI Slave MOSI is configured as Output, when we are using LPC2148 as SPI Master Instrumentation & Communication Unit
  • 5. • 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 Master 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. Steps for Slave Mode Instrumentation & Communication Unit
  • 6. START Set SPCCR Set SPCR Monitor SPIF bit Write data to SPDR Is SPIF set ? Read SPSR Read SPDR END No Yes SPI Initialization process Writing data to Data Registers Instrumentation & Communication Unit
  • 7. 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). 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. Instrumentation & Communication Unit
  • 8. SPCR (Control Register) This bit can be used to select the data length for SPI protocol The minimum data length is 8bits and maximum 16bits When BitEnable = 0 , data length is fixed & considered to be 8bits When BitEnable = 1 , data length depends upon the combinations of 11:8 bits of SPCR For example, we are using SPI compatible 12 bit ADC In this case, the ADC result will be of 12 bits BitEnable = 1 Bits 11: 8 = 1100 (Combination for 12 bits) 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 Bit 3: CPHA Bit 2: BitEnable Instrumentation & Communication Unit
  • 9. • 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. • 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 Bit 4: CPOL Instrumentation & Communication Unit
  • 10. • The bit is used to configure SPI block in Master/Slave Mode • MSTR = 0 Slave Mode • MSTR = 1 Master Mode Bit 5: MSTR • The bit decides the direction of bit transfer • LSBF = 0 MSB is transferred first • LSBF = 1 LSB is transferred first Bit 6: LSBF • 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 Instrumentation & Communication Unit
  • 11. When bit 2 of this register is 1, this field controls the number of bits per transfer: 1000 8 bits per transfer 1001 9 bits per transfer 1010 10 bits per transfer 1011 11 bits per transfer 1100 12 bits per transfer 1101 13 bits per transfer 1110 14 bits per transfer 1111 15 bits per transfer 0000 16 bits per transfer Bit 11:8 BITS Example: The target device is 12bit ADC, which is slave and LPC2148 is Master Bit 0 1 2 3 4 5 6 7 8 9 10 11 - - 1 0 0 1 0 0 1 1 0 0 Control Register (SPCR) Instrumentation & Communication Unit
  • 12. Some Imp points… 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). (pg 169) Instrumentation & Communication Unit
  • 13. Thank You !!! Instrumentation & Communication Unit