ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)
-
Upload
ciera-hosfield -
Category
Documents
-
view
227 -
download
0
Transcript of ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)
![Page 1: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/1.jpg)
ECE 371 Unit 13 - Part 1
Serial Peripheral Interface (SPI)
![Page 2: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/2.jpg)
Serial Peripheral Interface
• Synchronous Serial Interface
• Widely used to interface Peripheral Chips with Microcontrollers
• Much faster bit rate than asynchronous SCI method.
![Page 3: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/3.jpg)
• SPI system consist of one Master Device and one or more Slave Devices
• Master Device sends out a Serial Shift Clock signal (SCK) to all slaves, to serve as timing reference for the serial data transfer.
• No Start Bits or Stop Bits as used in SCI (asynchronous serial I/O method)
![Page 4: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/4.jpg)
• 3 SPI Channels on MC9S12Dp256B Microcontroller
• 4 Pins Associated with Each SPI Channel
- MISO (Serial input data for a Master, serial output data for a Slave)
- MOSI ((Serial output data for a Master, serial input data for a Slave)
- SCK (Serial data clock)
- SS (Slave select; for a system with a single slave, SS = 0 selects the Slave and SS = 1 selects the Master.
![Page 5: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/5.jpg)
Master/Slave SPI Interface
![Page 6: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/6.jpg)
![Page 7: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/7.jpg)
Parallel-to-Serial and Serial to Parallel-to-Serial Registers are needed to interface a peripheral device to the microcontroller using the SPI protocol.
• 74HC 595 - Serial-to-Parallel Converter Register
- Serial Input
- Parallel Output
- (Also serial output)
• 74HC 597 - Parallel-to Serial Converter Register
- Parallel Input
- Serial Output
- (Also Serial Input)
![Page 8: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/8.jpg)
74HC595 8-bit Shift Register(Serial to parallel converter)
Serial input
Parallel output
Serial output
![Page 9: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/9.jpg)
74HC595 8-bit Shift Register and 8-bit Storage
Serial input
ParallelOutput
Serial Output
![Page 10: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/10.jpg)
SPI Connections between the Microcontroller and a 74HC595 Register to implement an Output
Port
MOSI DS (Serial Data Input for 74HC595)
SCK SH_CP (“Shift” Clock Pulse)
SS ST_CP (Store Shift Register Data into Latch)
OE = “0” (Enable Latch Output Bus Drivers)
MR = “1” -- (Master Reset not active)
Microcontroller signal 74HC595 pin
![Page 11: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/11.jpg)
D7 D6 D5 D4 D3 D2 D1 D0
MOSI – Shifted into Shift Register
SCLK
SYNC or SS
Clock Latches
74HC595 8-bit Shift Registerwith Output Latches
![Page 12: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/12.jpg)
SYNC PULSE Transfer Shift Register Data to Data Latches when SYNC Pulse occursSet Flag to Signal that there is Received Data in Data Latches
Shift Data into Shift Register
Shift Data intoShift Register
SPI Overview
![Page 13: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/13.jpg)
Slave – 74HC595
![Page 14: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/14.jpg)
SerialDataOut
SS SCLK
Load Reset Serial Data In
74HC597 – 8 bit Parallel InSerial Out
ParallelInput
![Page 15: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/15.jpg)
SP Slave – 74HC597
LCLK = Load Parallel FF
![Page 16: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/16.jpg)
SPI1 and SPI2 can be implemented on Port P or Port H
SPI1 signals
If MODRR[5]=0
SPI2 signals
If MODRR[6]=0
SPI1 signals
If MODRR[5]=1
SPI2 signals
If MODRR[6]=1
![Page 17: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/17.jpg)
SPI0 can be implemented on Port M or Port S
SPI0 signals if
MODRR[4]=0
SPI0 signals if
MODRR[4]=1
![Page 18: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/18.jpg)
Module Routing Register
![Page 19: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/19.jpg)
SPI Channel 0 Routing
![Page 20: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/20.jpg)
SPI Channel 1 and 2 Routing
Use MODRR[5] = 0 and MODRR[6] = 0
![Page 21: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/21.jpg)
SPI Channel 1
• If SPI pin is output, then DDRx must set pin as out.
• SPI1 uses Port P on our System:– PP0 – MISO1 – In– PP1 – MOSI1 – Out– PP2 – SCK1 – Out– PP3 - SS1 – Out
![Page 22: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/22.jpg)
SPI Register Designations
• SPI1CR1, SPI1CR2, SPI1SR, SPI1DR, SPI1BR, DDRM, PTM, DDRP, PTP
• Laboratory– Port M is Used to Select 1 of 8 SPI Serial
Devices on Project Board– Port S Shares Pins with SPI Channel 0
![Page 23: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/23.jpg)
Project Board Laboratory
• 8 SPI Devices on Project Board
• Port M [6:4] Selects SPI Device– PM[4] = SS0– PM[5] = SS1– PM[6] = SS2
• D/A Converter is Device 5,
(SS2 SS1 SS0 = 1 0 1)
• SPI Slaves Implemented with 74HC595
![Page 24: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/24.jpg)
Slave Selection – 8 Slaves on Project Board
PM[4] => SS0PM[5] => SS1PM[6] => SS2
SS = PP[3]SS => S5
SER_DIS = “1”
Connected to gnd by jumper
![Page 25: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/25.jpg)
SPI Channel 1 – SPI1
• Port P[0] = MISO
• Port P[1] = MOSI
• Port P[2] = SCK
• Port P[3] = SS
![Page 26: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/26.jpg)
SPI Channel 1 Definitions
#define SPI1CR1 _P(0xF0)#define SPI1CR2 _P(0xF1)#define SPI1BR _P(0xF2) #define SPI1SR _P(0xF3)#define SPI1DR _P(0xF5)
![Page 27: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/27.jpg)
SPI Data Register
![Page 28: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/28.jpg)
SPI Baud Rate Register
Baud = BusClock/BaudRateDivisor = 2000000/BaudRateDivisor
![Page 29: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/29.jpg)
![Page 30: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/30.jpg)
![Page 31: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/31.jpg)
SPI Control Register 1
![Page 32: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/32.jpg)
SPI Control Register 1
![Page 33: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/33.jpg)
SPI Control Register 1
![Page 34: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/34.jpg)
SPI Control Register 2
![Page 35: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/35.jpg)
![Page 36: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/36.jpg)
![Page 37: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/37.jpg)
![Page 38: ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)](https://reader035.fdocuments.us/reader035/viewer/2022062518/56649ca65503460f94968b5b/html5/thumbnails/38.jpg)