E N D
SPI • The Serial Peripheral Interface Bus or SPI (pronounced as either ess-pee-eye or spy) bus is a synchronous serial data link standard, named by Motorola, that operates in full duplex mode. Devices communicate in master/slave mode where the master device initiates the data frame. Multiple slave devices are allowed with individual slave select (chip select) lines. Sometimes SPI is called a four-wire serial bus, contrasting with three-, two-, and one-wire serial buses. SPI is often referred to as SSI (Synchronous Serial Interface). -from Wiki http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
SPI-Interface • The SPI bus specifies four logic signals: • SCLK: serial clock (output from master); • MOSI: master output, slave input (output from master); • MISO: master input, slave output (output from slave); • SS: slave select (active low, output from master). The SDI/SDO (DI/DO, SI/SO) convention requires that SDO on the master be connected to SDI on the slave, and vice-versa. Chip select polarity is rarely active high, although some notations (such as SS or CS instead of nSS or nCS) suggest otherwise. -from Wiki http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
SPI in MSP430 SPI Mode
SPI in MSP430 Clock polarity and phase http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
SPI01_MASTER.C • 以示波器觀察CLK及SIMO訊號變化 CLK SIMO • MSB-first
SPI01_MASTER.C • 0x01 • 0x03 • 0x05 • 0x50 • 0x80 CLK Why?? SIMO
SPI01_SLAVE.C • 由slave接收資料 • 兩個人一組,一位執行SPI01_MASTER發送資料,另一位執行SPI01_SLAVE接收資料觀察UCA0RXBUF的值 SPI01_MASTER SIMO- SOMI- CLK- GND- SPI01_SLAVE -SIMO -SOMI -CLK -GND • 上述哪一條線可拿掉而不影響結果??Why?
SPI02_MASTER.C • 兩個人一組,一位執行SPI02_MASTER發送資料,另一位執行SPI02_SLAVE接收資料,個別觀察UCA0RXBUF的值 SPI01_MASTER SIMO- SOMI- CLK- GND- SPI01_SLAVE -SIMO -SOMI -CLK -GND
SPI02_SLAVE.C CLK SIMO SOMI • Synchronous • 請參考上圖訊號,思考SPI傳輸特性。 資料傳輸時,何者主動?何者被動?
SPI03_MASTER.C • 中斷 • 兩個人一組,一位執行SPI03_MASTER發送資料,另一位執行SPI03_SLAVE接收資料,設定中斷,個別觀察UCA0RXBUF的值 SPI01_MASTER SIMO- SOMI- CLK- GND- SPI01_SLAVE -SIMO -SOMI -CLK -GND
SPI03_SLAVE.C • 試拔除所有連線,觀察MASTER端傳資料出去後是否仍會進入RX中斷? 為什麼?
SPI04_MASTER.C • 中斷 • 兩個人一組,一位執行SPI04_MASTER發送資料,另一位執行SPI04_SLAVE接收資料, SPI04_SLAVE 先執行,觀察兩端閃燈狀況。 SPI01_MASTER SIMO- SOMI- CLK- GND- SPI01_SLAVE -SIMO -SOMI -CLK -GND
SPI04_SLAVE.C • 為何MASTER端總是比SLAVE端慢一次?
SPI05_MASTER.C • 讀取sensor值 • 兩個人一組,一位執行SPI05_MASTER發送資料,另一位執行SPI05_SLAVE接收資料, SPI05_SLAVE 先執行,觀察MASTER端收到的值。 SPI01_MASTER SIMO- SOMI- CLK- GND- SPI01_SLAVE -SIMO -SOMI -CLK -GND • 試想,Master端要讀Slave的值,為何需要傳資料給Slave??
SPI05_SLAVE.C • 試將紅框那一行移除,重新執行上述步驟,會有甚麼差異?