You are on page 1of 12

Embedded Systems

Engineering
By Nushara Wedasingha
Mphil Candidate(AI), Bsc.(Hons) in
EEE
EEE Department
Faculty of Engineering
Sri Lanka Institute of Information
Technology
What is SPI?
• It is stands for “Serial Peripheral Interface”.
• It was found in 1985 by Motorola to increase the throughput speed of I2C.
• To Obtain that speed a new signal was introduced where information from the MCU is sent
to the peripheral known as “Slave”.
• SPI is bit expensive than I2C because it requires more logic gates to analyze the additional
signal.
• It is found in NOR flash, EEPROM, EERAM, SRAM, LCD, SD and RTC.
• This is also known as the “Four Wired Bus” because it requires four wires to complete the
communication.
Four Modes of SPI
It is used to build the relationship between the slave select, data, and clock lines with clock
phase and clock polarity.
• Non-Inverted Clock Polarity.
1. Mode 1: Clock phase is configured for sampling data at falling edge and
shifting data at rising edge.
2. Mode 2: Clock phase is configured for sampling data at rising edge and
shifting data at falling edge.
• Inverted Clock Polarity.
3. Mode 3: Clock phase is configured for sampling data at falling edge and
shifting data at rising edge.
4. Mode 4: Clock phase is configured for sampling data at rising edge and
shifting data at falling edge.
Key Terms

• CLK : - Source Clock

• CK : - Chip or Slave Select

• MISO (Master in Slave Out): - Master is Receiving Slave is Sending.

• MOSI (Master Out Slave in): - Master is Sending Slave is Receiving.


Methodology of Coding
Setting Up SPI (UCACTLW0 Register)

Put Ports into Activate Master


Choose SMCLK Set Baud Rate
Software Rest State Mode

Configuring Port (PxSEL Register)

Set SCLK Port Set MOSI Port Set MISO Port

Switch off Rest Send data through UCA0TxBUF


UCACTLW 0
PxSEL
PxSEL1 &=~BIT5; // Clear Pin 5
PxSEL0 I = BIT5; // Setting pin 5 to SCLK

PxSEL1 &= ~BIT7 // Clear Pin 7


PxSEL0 I = BIT7// Setting Pin 7 for MISO

PxSEL1 &= ~BIT6 // Clear Pin 7


PxSEL0 I = BIT6// Setting Pin 6 for MOSI
Transmitting Data

UCA0TXBUF = The Data that You are going to send to Slave.


Example Code

• Setting Up SPI

UCA0CTLW0 I= UCSWRST; // Set Port A0 in Reset Mode


UCA0CTLW0 I= UCSSE_SMCLK// Choosing SMCLK clock as Master Clock
UCA0BRW0 = 10// Setting up Baud Rate
UCA0CTLW0 I= UCSYNC; // Activating SPI Mode
UCA0CTLW0 I= UCMST; // Activating the Master Mode
Example Code

• Setting Up Pin

P1SEL1 &=~BIT5; // Clear Pin 5


P1SEL0 I = BIT5; // Setting pin 5 to SCLK

P1SEL1 &= ~BIT7 // Clear Pin 7


P1SEL0 I = BIT7// Setting Pin 7 for MISO

P1SEL1 &= ~BIT6 // Clear Pin 7


P1SEL0 I = BIT6// Setting Pin 6 for MOSI
Example Code

• Switching off Reset Mode of Port A0

UCA0CTLW0 &= ~UCSWRST

• Transmitting Data

While(1) {

UCA0TXBUF = 0X4D

}
THANK YOU

You might also like