SlideShare a Scribd company logo
1 of 12
Serial Peripheral Interface (SPI)
SPI = Simple, 3 wire, full duplex, synchronous serial data transfer
Interfaces to many devices, even many non-SPI peripherals
Can be a master or slave interface
4 interface pins:
-MOSI master out slave in
-MIOS master in slave out
-SCK serial clock
-SS_n slave select
3 registers:
-SPCR control register
-SPSR status register
-SPDR data register
Serial Peripheral Interface (SPI)
Full duplex, synchronous serial data transfer
Data is shifted out of the master's (mega128) 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.
slave SPI devicemaster SPI device
Serial Peripheral Interface (SPI)
Slave Select... use it carefully!
In master mode:
-SPI interface has no control of SS_n
-User software has full control of SS_n (Port B, bit 0)
-If configured as output, it’s a general purpose output
-If configured as input, it must be held high, else you will enter slave mode
We will use SPI in master mode, full duplex
Serial Peripheral Interface (SPI)
SPI Control Register (SPCR)
data order: if set, LSB is
transmitted first
interrupt enable: if set, interrupt
occurs when SPI interrupt flag
and global interrupt enable are set
spi enable: if set, SPI interface
is enabled
master/slave select: if set,
SPI in master mode
clock polarity:
'0' SCK low in idle
'1' SCK high in idle
clock phase:
'0' leading edge sample, trailing edge setup
'1' leading edge setup, trailing edge sample
clock rate
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)
Serial Peripheral Interface (SPI)
SPI Status Register (SPSR)
interrupt flag: set when serial
transfer is complete
write collision: set if SPDR is
written during a receive transfer
2x clock rate: if set, doubles
clock rate in master mode
reserved bits
SPI Data Register (SPDR)
SPDR is a read/write register used for data transfer. Writing SPDR sends data
out MOSI. Reading SPDR gets the data that was clocked into MISO.
Serial Peripheral Interface (SPI)
Mega128 LCD interface
SCK, PB1
LCD strobe, PF3
MOSI, PB2
enable pulse generator
9-bit shift register
Serial Peripheral Interface (SPI)
SPI Application - Code
/*********************************************************************/
// spi_init
//Initializes the SPI port on the mega128. Does not do any further
//external device specific initializations.
/*********************************************************************/
void spi_init(void){
DDRB = DDRB | 0x07; //Turn on SS, MOSI, SCLK (SS is output)
SPCR |= (1<<SPEN) | (1<<MSTR); //spi enabled, master, low polarity, msb 1st
SPSR |= (1<<SPI2X); //run at i/o clock div 2
}//spi_init
/***********************************************************************/
// digi_pot_send
//Sends command and data to the digital pot. SPI device chip select is
//active low and is connected to port F bit 2. Total of 16 bits are sent.
//One byte for control and one byte as data passed in.
/***********************************************************************/
void digi_pot_send(uint8_t data){
PORTF &= 0xFB; //port F bit 2, assert active low
SPDR = 0x13; //send command byte (fixed value)
while (bit_is_clear(SPSR,SPIF)) {} //wait till data is sent out
SPDR = data; //send data byte
while (bit_is_clear(SPSR,SPIF)) {} //wait till data is sent out
PORTF |= 0x04; //port F bit 2, deassert to logic high
} //digi_pot_send
Serial Peripheral Interface (SPI)
Typical SPI IC (MCP42010)
Serial Peripheral Interface (SPI)
74HC595 – A perfectly fine SPI peripheral
Serial Peripheral Interface (SPI)
What if you want only to read the SPI port?
To get the SPI clock to run, a "dummy" write is made to the SPI
SPDR register. This starts the clock running so the data on MISO
is brough into the uC.
If no peripherals are selected, the outgoing data will be ignored. If you
are clever, you can send data out and bring data in at the same time.
/*********************************************************************/
// spi_read
//Reads the SPI port.
/*********************************************************************/
uint8_t spi_read(void){
SPDR = 0x00; //"dummy" write to SPDR
while (bit_is_clear(SPSR,SPIF)){} //wait till 8 clock cycles are done
return(SPDR); //retrun incoming data from SPDR
}//read_spi
Serial Peripheral Interface (SPI)
74HC165 – Another fine SPI peripheral
Serial Peripheral Interface (SPI)
SPI “Gotchas”
“Now my board won’t program.”
SPI shares SCK with programming interface. If it won’t program anymore,
you likely messed up SCK.
“SPI acts totally wierd.”
Often a symptom of SS_n being configured as an input and being left to float
or allowed to go high. SPI goes in and out between slave and master modes.
“I never get data to the SPI device.”
Is clock correctly oriented ? Did you assert the device chip select?
(hint: put SPI write inside a “tight” loop and check with scope. Watch
SCK, data, and chip select)
"SPI device interactions:" When programming, the programmer first does a chip
reset. When the mega128 resets, all pins are set to input with high impedance
(floating). If a SPI device is on the SPI bus, it's chip-select may
float low and enable the device, and SPI data will crash the programming data.
Adding a pull-up resistor to chip selects will solve this problem.

More Related Content

What's hot

itft-Microcontriller 8051
itft-Microcontriller 8051itft-Microcontriller 8051
itft-Microcontriller 8051Shifali Sharma
 
15. memory interfacing i
15. memory interfacing i15. memory interfacing i
15. memory interfacing isandip das
 
28. 8251 programmable communication interface
28. 8251 programmable communication interface28. 8251 programmable communication interface
28. 8251 programmable communication interfacesandip das
 
16. memory interfacing ii
16. memory interfacing ii16. memory interfacing ii
16. memory interfacing iisandip das
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051Muthu Manickam
 
advancsed microprocessor and interfacing
advancsed microprocessor and interfacingadvancsed microprocessor and interfacing
advancsed microprocessor and interfacing@zenafaris91
 
8051-microcontroller
8051-microcontroller8051-microcontroller
8051-microcontrollerjhcid
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp portTeju Kotti
 
Iosystemspre final-160922112930
Iosystemspre final-160922112930Iosystemspre final-160922112930
Iosystemspre final-160922112930marangburu42
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Ganesh Ram
 
23. serial and parallel data communication
23. serial and parallel data communication23. serial and parallel data communication
23. serial and parallel data communicationsandip das
 
Basics of peripheral devices and Working
Basics of peripheral devices and WorkingBasics of peripheral devices and Working
Basics of peripheral devices and WorkingDr.YNM
 
Serial Communication In Atmega 16
Serial Communication In Atmega 16Serial Communication In Atmega 16
Serial Communication In Atmega 16Suren Kumar
 

What's hot (20)

itft-Microcontriller 8051
itft-Microcontriller 8051itft-Microcontriller 8051
itft-Microcontriller 8051
 
15. memory interfacing i
15. memory interfacing i15. memory interfacing i
15. memory interfacing i
 
8251 USART
8251 USART8251 USART
8251 USART
 
28. 8251 programmable communication interface
28. 8251 programmable communication interface28. 8251 programmable communication interface
28. 8251 programmable communication interface
 
8051 microprocessor
8051 microprocessor8051 microprocessor
8051 microprocessor
 
16. memory interfacing ii
16. memory interfacing ii16. memory interfacing ii
16. memory interfacing ii
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051
 
advancsed microprocessor and interfacing
advancsed microprocessor and interfacingadvancsed microprocessor and interfacing
advancsed microprocessor and interfacing
 
8051-microcontroller
8051-microcontroller8051-microcontroller
8051-microcontroller
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp port
 
itft-Clock generator
itft-Clock generatoritft-Clock generator
itft-Clock generator
 
Iosystemspre final-160922112930
Iosystemspre final-160922112930Iosystemspre final-160922112930
Iosystemspre final-160922112930
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
 
23. serial and parallel data communication
23. serial and parallel data communication23. serial and parallel data communication
23. serial and parallel data communication
 
Basics of peripheral devices and Working
Basics of peripheral devices and WorkingBasics of peripheral devices and Working
Basics of peripheral devices and Working
 
Serial Communication In Atmega 16
Serial Communication In Atmega 16Serial Communication In Atmega 16
Serial Communication In Atmega 16
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
8051 block diagram
8051 block diagram8051 block diagram
8051 block diagram
 
8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
8155 PPI
8155 PPI8155 PPI
8155 PPI
 

Viewers also liked

Presentación conductividad eléctrica
Presentación conductividad eléctricaPresentación conductividad eléctrica
Presentación conductividad eléctricaJuan Camero
 
Naskah Visi, Misi dan Program
Naskah Visi, Misi dan Program Naskah Visi, Misi dan Program
Naskah Visi, Misi dan Program Info Pekalongan
 
XDR40 excavator drill attachment
XDR40 excavator drill attachmentXDR40 excavator drill attachment
XDR40 excavator drill attachmentAidas Baubonis
 
Visi misi Dwi Heri Sutarip Tulis Widodo OK
Visi misi Dwi Heri Sutarip Tulis Widodo OKVisi misi Dwi Heri Sutarip Tulis Widodo OK
Visi misi Dwi Heri Sutarip Tulis Widodo OKInfo Pekalongan
 
Disadvantages of Genetic Modification Organisms (GMOs)
Disadvantages of Genetic Modification Organisms (GMOs)Disadvantages of Genetic Modification Organisms (GMOs)
Disadvantages of Genetic Modification Organisms (GMOs)brenel93
 
Contract of Indemnity and Guarantee
Contract of Indemnity and GuaranteeContract of Indemnity and Guarantee
Contract of Indemnity and GuaranteeFaizanur1984
 

Viewers also liked (11)

Presentación conductividad eléctrica
Presentación conductividad eléctricaPresentación conductividad eléctrica
Presentación conductividad eléctrica
 
Naskah Visi, Misi dan Program
Naskah Visi, Misi dan Program Naskah Visi, Misi dan Program
Naskah Visi, Misi dan Program
 
XDR40 excavator drill attachment
XDR40 excavator drill attachmentXDR40 excavator drill attachment
XDR40 excavator drill attachment
 
Visi misi Dwi Heri Sutarip Tulis Widodo OK
Visi misi Dwi Heri Sutarip Tulis Widodo OKVisi misi Dwi Heri Sutarip Tulis Widodo OK
Visi misi Dwi Heri Sutarip Tulis Widodo OK
 
Visi misi alexsae
Visi misi alexsaeVisi misi alexsae
Visi misi alexsae
 
Mohamed_Amin_Tayechi_Ben_Majid 2
Mohamed_Amin_Tayechi_Ben_Majid 2Mohamed_Amin_Tayechi_Ben_Majid 2
Mohamed_Amin_Tayechi_Ben_Majid 2
 
To cs
To csTo cs
To cs
 
Mgt 210 project slide
Mgt 210 project slideMgt 210 project slide
Mgt 210 project slide
 
Disadvantages of Genetic Modification Organisms (GMOs)
Disadvantages of Genetic Modification Organisms (GMOs)Disadvantages of Genetic Modification Organisms (GMOs)
Disadvantages of Genetic Modification Organisms (GMOs)
 
Testing reading
Testing readingTesting reading
Testing reading
 
Contract of Indemnity and Guarantee
Contract of Indemnity and GuaranteeContract of Indemnity and Guarantee
Contract of Indemnity and Guarantee
 

Similar to Spi (1)

Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral InterfaceChirag Parikh
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral InterfaceAnurag Tomar
 
SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SUNODH GARLAPATI
 
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Aarav Soni
 
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.pptxnaveen088888
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolAditya Porwal
 
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docx
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docxD-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docx
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docxearleanp
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemsRaghunath reddy
 
What's going on with SPI
What's going on with SPI What's going on with SPI
What's going on with SPI Mark Brown
 
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
 
spi-180501092933-converted.pptx
spi-180501092933-converted.pptxspi-180501092933-converted.pptx
spi-180501092933-converted.pptxsauryakumar3
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Dhaval Kaneria
 
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 developmentFastBit Embedded Brain Academy
 
Cisco router basic
Cisco router basicCisco router basic
Cisco router basicTapan Khilar
 

Similar to Spi (1) (20)

Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)
 
Spi in arm7(lpc2148)
Spi in arm7(lpc2148)Spi in arm7(lpc2148)
Spi in arm7(lpc2148)
 
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
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
 
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docx
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docxD-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docx
D-7-17 Interface an 8-bit serial device using SPI- Thecontrol pin is i.docx
 
communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systems
 
What's going on with SPI
What's going on with SPI What's going on with SPI
What's going on with SPI
 
Assembler4
Assembler4Assembler4
Assembler4
 
At89 s8252
At89 s8252At89 s8252
At89 s8252
 
10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt10_2Starting with serial_II.ppt
10_2Starting with serial_II.ppt
 
Introduction to embedded systems
Introduction to embedded systemsIntroduction to embedded systems
Introduction to embedded systems
 
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)
 
spi-180501092933-converted.pptx
spi-180501092933-converted.pptxspi-180501092933-converted.pptx
spi-180501092933-converted.pptx
 
SPI Bus Protocol
SPI Bus ProtocolSPI Bus Protocol
SPI Bus Protocol
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
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
 
Cisco router basic
Cisco router basicCisco router basic
Cisco router basic
 
89s52 2
89s52 289s52 2
89s52 2
 

Recently uploaded

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Spi (1)

  • 1. Serial Peripheral Interface (SPI) SPI = Simple, 3 wire, full duplex, synchronous serial data transfer Interfaces to many devices, even many non-SPI peripherals Can be a master or slave interface 4 interface pins: -MOSI master out slave in -MIOS master in slave out -SCK serial clock -SS_n slave select 3 registers: -SPCR control register -SPSR status register -SPDR data register
  • 2. Serial Peripheral Interface (SPI) Full duplex, synchronous serial data transfer Data is shifted out of the master's (mega128) 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. slave SPI devicemaster SPI device
  • 3. Serial Peripheral Interface (SPI) Slave Select... use it carefully! In master mode: -SPI interface has no control of SS_n -User software has full control of SS_n (Port B, bit 0) -If configured as output, it’s a general purpose output -If configured as input, it must be held high, else you will enter slave mode We will use SPI in master mode, full duplex
  • 4. Serial Peripheral Interface (SPI) SPI Control Register (SPCR) data order: if set, LSB is transmitted first interrupt enable: if set, interrupt occurs when SPI interrupt flag and global interrupt enable are set spi enable: if set, SPI interface is enabled master/slave select: if set, SPI in master mode clock polarity: '0' SCK low in idle '1' SCK high in idle clock phase: '0' leading edge sample, trailing edge setup '1' leading edge setup, trailing edge sample clock rate 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)
  • 5. Serial Peripheral Interface (SPI) SPI Status Register (SPSR) interrupt flag: set when serial transfer is complete write collision: set if SPDR is written during a receive transfer 2x clock rate: if set, doubles clock rate in master mode reserved bits SPI Data Register (SPDR) SPDR is a read/write register used for data transfer. Writing SPDR sends data out MOSI. Reading SPDR gets the data that was clocked into MISO.
  • 6. Serial Peripheral Interface (SPI) Mega128 LCD interface SCK, PB1 LCD strobe, PF3 MOSI, PB2 enable pulse generator 9-bit shift register
  • 7. Serial Peripheral Interface (SPI) SPI Application - Code /*********************************************************************/ // spi_init //Initializes the SPI port on the mega128. Does not do any further //external device specific initializations. /*********************************************************************/ void spi_init(void){ DDRB = DDRB | 0x07; //Turn on SS, MOSI, SCLK (SS is output) SPCR |= (1<<SPEN) | (1<<MSTR); //spi enabled, master, low polarity, msb 1st SPSR |= (1<<SPI2X); //run at i/o clock div 2 }//spi_init /***********************************************************************/ // digi_pot_send //Sends command and data to the digital pot. SPI device chip select is //active low and is connected to port F bit 2. Total of 16 bits are sent. //One byte for control and one byte as data passed in. /***********************************************************************/ void digi_pot_send(uint8_t data){ PORTF &= 0xFB; //port F bit 2, assert active low SPDR = 0x13; //send command byte (fixed value) while (bit_is_clear(SPSR,SPIF)) {} //wait till data is sent out SPDR = data; //send data byte while (bit_is_clear(SPSR,SPIF)) {} //wait till data is sent out PORTF |= 0x04; //port F bit 2, deassert to logic high } //digi_pot_send
  • 8. Serial Peripheral Interface (SPI) Typical SPI IC (MCP42010)
  • 9. Serial Peripheral Interface (SPI) 74HC595 – A perfectly fine SPI peripheral
  • 10. Serial Peripheral Interface (SPI) What if you want only to read the SPI port? To get the SPI clock to run, a "dummy" write is made to the SPI SPDR register. This starts the clock running so the data on MISO is brough into the uC. If no peripherals are selected, the outgoing data will be ignored. If you are clever, you can send data out and bring data in at the same time. /*********************************************************************/ // spi_read //Reads the SPI port. /*********************************************************************/ uint8_t spi_read(void){ SPDR = 0x00; //"dummy" write to SPDR while (bit_is_clear(SPSR,SPIF)){} //wait till 8 clock cycles are done return(SPDR); //retrun incoming data from SPDR }//read_spi
  • 11. Serial Peripheral Interface (SPI) 74HC165 – Another fine SPI peripheral
  • 12. Serial Peripheral Interface (SPI) SPI “Gotchas” “Now my board won’t program.” SPI shares SCK with programming interface. If it won’t program anymore, you likely messed up SCK. “SPI acts totally wierd.” Often a symptom of SS_n being configured as an input and being left to float or allowed to go high. SPI goes in and out between slave and master modes. “I never get data to the SPI device.” Is clock correctly oriented ? Did you assert the device chip select? (hint: put SPI write inside a “tight” loop and check with scope. Watch SCK, data, and chip select) "SPI device interactions:" When programming, the programmer first does a chip reset. When the mega128 resets, all pins are set to input with high impedance (floating). If a SPI device is on the SPI bus, it's chip-select may float low and enable the device, and SPI data will crash the programming data. Adding a pull-up resistor to chip selects will solve this problem.