Re: 如何讓兩個CPU使用SPI通訊(master & slave)?
|
||||
---|---|---|---|---|
資深會員
|
對於 SPI 的簡介可參考Wiki
裡面提到 CPOL,CPHA 對應 CKP, Not CKE CKE := Not CPHA CKE = 1 指資料在第一個 edge 有效 CKE = 0 指資料在第二個 edge 有效 所以 當 CKE=1 時需設 SS enabled, -> SSPM<3:0>=0100 也就是說 SS 接腳必須用 (not optional), 詳見後述 當 CKE=0 時 SS 可用可不用 SS 接腳可做其他用途 (optional) 若是用 Synchronous Slave mode 則必須設 SS enabled, -> SSPM<3:0>=0100 不管 CKE 值為何 若 SS enabled, 當 SS pin 為 high 時 SPI 的 shift counter 會歸零 所以萬一資料傳到一半 SS pin 忽然變為 high 再變為 low 則資料從 bit7 開始傳起 --------------- SSPM<3:0>=0100 使用 SS pin (Slave mode) SSPM<3:0>=0101 不使用 SS pin (Slave mode) --------------- 簡單來講 SPI 的傳輸 全靠 SCK 來控制 一有 clock 就開試運作 若 CKE=1, 因 slave 並不知道何時將資料 放到 SDO 接腳 若在第一個 edge, Master 就讀資料就有問題 所以須靠 SS (slave select) 來幫助 當 slave 的 SS 變為 low 時, slave 就知道要開始傳輸資料了 在 SDO 就會先放 bit7, 所以當第一個 clock 的第一個edge時 SDO 已有資料準備好 若 CKE=0, 因 clock 一有變化(第一個edge) slave 就知傳輸要開始 於是就把資料 bit7 送到 SDO 在第二個 edge 時就已 ready, 因此並不需用到 SS pin
發表於: 2007/11/23 15:43
|
|||
|
Re: 如何讓兩個CPU使用SPI通訊(master & slave)?
|
||||
---|---|---|---|---|
版主
|
CKE & CKP 是用來設定 SPI 的 Mode 共有四種 Mode 00, 01 ,10, 11。Master 及 Slave 兩邊都要設成一樣的 Mode 後才可以溝通。所謂 Mode 就是 SCK 是在上升緣或下降緣時擷取資料。
/SS pin 在 Slave 時有效,顧名思義 SS 就是 Slave Select 的功能,把她想成 /CS (Chip Select) 的功能就好了。一般在 Master 端是以一個 I/O 腳的輸出來控制 Slave 的 SS 腳,用來 Enable SPI Slave 的。
發表於: 2007/11/21 14:03
|
|||
|
如何讓兩個CPU使用SPI通訊(master & slave)?
|
||||
---|---|---|---|---|
資深會員
|
大家好:
個人剛接觸SPI,最主要問題是slave那邊的設定問題? 1.不知/SS及CKE的關係? 2.若不用/SS是否可行? 請指教,Thanks.
發表於: 2007/11/21 13:51
|
|||
|