2
Most read
3
Most read
6
Most read
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

PPTX
Serial Peripheral Interface
PPT
SPI Bus Protocol
PPTX
Spi in arm7(lpc2148)
PPTX
Internal Architecture of 8086| msbte sem 4 microprocessor
PDF
SPI Protocol
PPTX
Pic ppt 13104022(4th_year)
PPTX
SPI introduction(Serial Peripheral Interface)
PPTX
Interfacing with peripherals: analog to digital converters and digital to ana...
Serial Peripheral Interface
SPI Bus Protocol
Spi in arm7(lpc2148)
Internal Architecture of 8086| msbte sem 4 microprocessor
SPI Protocol
Pic ppt 13104022(4th_year)
SPI introduction(Serial Peripheral Interface)
Interfacing with peripherals: analog to digital converters and digital to ana...

What's hot (20)

PDF
PAI Unit 2 Segmentation in 80386 microprocessor
PPT
PPT
I2C Protocol
PPTX
5.programmable interval timer 8253
PPTX
Serial peripheral Interface - Embedded System Protocol
PPT
Serial Peripheral Interface(SPI)
PPTX
8257 DMA Controller
PPTX
Microprocessor 8086
PPT
AMBA_APB_pst
PPTX
Stack Memory Organization of 8086 Microprocessor
PPT
Spi master core verification
PDF
The I2C Interface
PPTX
I2C Protocol
PPT
PDF
BUilt-In-Self-Test for VLSI Design
PPTX
Programmable peripheral interface 8255
PDF
Memory interfacing of microcontroller 8051
PDF
Uvm presentation dac2011_final
PDF
I2C BUS PROTOCOL
PPTX
I2c buses
PAI Unit 2 Segmentation in 80386 microprocessor
I2C Protocol
5.programmable interval timer 8253
Serial peripheral Interface - Embedded System Protocol
Serial Peripheral Interface(SPI)
8257 DMA Controller
Microprocessor 8086
AMBA_APB_pst
Stack Memory Organization of 8086 Microprocessor
Spi master core verification
The I2C Interface
I2C Protocol
BUilt-In-Self-Test for VLSI Design
Programmable peripheral interface 8255
Memory interfacing of microcontroller 8051
Uvm presentation dac2011_final
I2C BUS PROTOCOL
I2c buses
Ad

Viewers also liked (20)

PDF
Lpc2148 i2c
PPTX
Timer counter in arm7(lpc2148)
PPTX
Serial communication in LPC2148
PPSX
Serial Peripherical Interface (SPI)
PPTX
Serial peripheral interface
DOCX
Arm7 Interfacing examples
PPTX
LPC 2148 ARM MICROCONTROLLER
PPT
PPT
Interfacing Bluetooth Modules with 8051 Microcontroller
DOCX
MONIKA SIYAL RESUME
PDF
7508 dcf ed01
PPTX
Cyber crime
PPT
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
PPTX
Broadband networking through human body
PDF
L T A Activities@IITB-Amool
PPT
Stellaris® 9000 Family of ARM® Cortex™-M3
PDF
The RoboCV Workshop
PDF
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
PDF
PDF
Arm cm3 architecture_and_programmer_model
Lpc2148 i2c
Timer counter in arm7(lpc2148)
Serial communication in LPC2148
Serial Peripherical Interface (SPI)
Serial peripheral interface
Arm7 Interfacing examples
LPC 2148 ARM MICROCONTROLLER
Interfacing Bluetooth Modules with 8051 Microcontroller
MONIKA SIYAL RESUME
7508 dcf ed01
Cyber crime
Study on 32-bit Cortex - M3 Powered MCU: STM32F101
Broadband networking through human body
L T A Activities@IITB-Amool
Stellaris® 9000 Family of ARM® Cortex™-M3
The RoboCV Workshop
ARM Cortex -M3 based Motor Controling with Infineon Embedded Power ICs
Arm cm3 architecture_and_programmer_model
Ad

Similar to SPI Protocol in LPC2148 (20)

PDF
Welcome to International Journal of Engineering Research and Development (IJERD)
PPTX
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
PPTX
I2 c and mpu6050 basics
PPTX
INTERFACING 8051-MICROCONTROLLER with timer and display
PPTX
UNIT V - INTERFACING MICROCONTROLLER (1).pptx
PPTX
Introduction to PIC.pptx
PPTX
LPC2148 SPI (Serial Peripheral Interface).pptx
DOCX
moving message display of lcd
PDF
PPTX
8051 SERIAL PORTS.pptx
PPTX
PIC 16F877 micro controller by Gaurav raikar
PPTX
Peripherals and interfacing
PDF
digitalvoltmeterusing805112b2-170214173216 (1).pdf
PPTX
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
PPTX
Microcontrollers and microprocessors in electrical communication engineering....
PDF
Raspberry Pi - Lecture 3 Embedded Communication Protocols
PPT
10_2Starting with serial_II.ppt
PDF
Design and Fabrication of 4-bit processor
PPTX
Microcontroller 8051 features and applications
PPTX
8051 MICROCONTROLLER ARCHITECTURE.pptx
Welcome to International Journal of Engineering Research and Development (IJERD)
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
I2 c and mpu6050 basics
INTERFACING 8051-MICROCONTROLLER with timer and display
UNIT V - INTERFACING MICROCONTROLLER (1).pptx
Introduction to PIC.pptx
LPC2148 SPI (Serial Peripheral Interface).pptx
moving message display of lcd
8051 SERIAL PORTS.pptx
PIC 16F877 micro controller by Gaurav raikar
Peripherals and interfacing
digitalvoltmeterusing805112b2-170214173216 (1).pdf
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
Microcontrollers and microprocessors in electrical communication engineering....
Raspberry Pi - Lecture 3 Embedded Communication Protocols
10_2Starting with serial_II.ppt
Design and Fabrication of 4-bit processor
Microcontroller 8051 features and applications
8051 MICROCONTROLLER ARCHITECTURE.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