Re: dsPIC30F2010 I2C 使用問題
|
||||
---|---|---|---|---|
新會員
|
不好意思....
我還是找不出問題!! 附上程式, 是否程式程序出問題.... I2C Slave中斷副程式... void _attribute_((__interrupt__)) _SI2CInterrupt(void){unsigned char Called_ADR; unsigned char I2CS_RxBuf; if(I2CSTATbits.D_A){ I2CS_RxBuf = SlaveReadI2C(); I2CCONbits.SCLREL=1; } else{ Called_ADR = SlaveReadI2C(); if(I2CSTATbits.R_W){ SlaveWriteI2C(0xAA); } } IFS0bits.SI2CIF = 0; } I2C Master 程式............ void I2C_Master_Receiver(unsigned char I2CS_ADR, unsigned char I2CM_RxBuf){ I2C_Start_Bit(); I2C_MWR_Byte(I2CS_ADR+1); I2CM_RxBuf = MasterReadI2C(); NotAckI2C(); I2C_Stop_Bit(); return; }
發表於: 2008/4/10 17:41
|
|||
|
Re: dsPIC30F2010 I2C 使用問題
|
||||
---|---|---|---|---|
版主
|
參考一下 "dsPIC30F Module Training - I2C 教材及練習 " 裡的 code Example for I2C Slive :
http://www.microchip.com.tw/modules/mydownloads/viewcat.php?cid=4
發表於: 2008/4/9 15:10
|
|||
|
Re: dsPIC30F2010 I2C 使用問題
|
||||
---|---|---|---|---|
新會員
|
Slave在接收完訊號時, 馬上使用C30資料庫裡的副程式
SlaveWriteI2C(0xAA); 其內容是.... void SlaveWriteI2C(unsigned char data_out) { /* data transferred to I2CTRN reg */ I2CTRN = data_out; /* Release the clock */ I2CCONbits.SCLREL = 1; } 而且, 我也確定I2CCONbits.SCLREL有等於1.... 不過還是一樣沒有訊號
發表於: 2008/4/9 13:46
|
|||
|
Re: dsPIC30F2010 I2C 使用問題
|
||||
---|---|---|---|---|
版主
|
那這樣就有問題了,Slave 端處理完接收資料離開中斷前是否有將 SCL 放開,因為 SCL 在 I2C 裡是可以用來做 Handshake 的,Slave hold 住 SCL 的話 Master 是不會送出任何訊號出來的。
發表於: 2008/4/3 17:20
|
|||
|
Re: dsPIC30F2010 I2C 使用問題
|
||||
---|---|---|---|---|
新會員
|
這時候 SCL & SDA都在Low livel.....
OK ! 我會先是一下Master是否正常讀寫!! 謝謝....
發表於: 2008/4/3 17:04
|
|||
|
Re: dsPIC30F2010 I2C 使用問題
|
||||
---|---|---|---|---|
版主
|
請問這時候 SCL 是否在 Hi level ?
一般在使用 I2C 時,以 Slave 端比較複雜也比較不好寫。 建議以先用一個 24LC04 EEPROM 先當一下 I2C Slave,先確定 Master 的程式能正確讀、寫 EEPROM 的內容無誤後,再來測試 Slave 的程式。這樣比較好釐清是誰的錯誤。 有關I2C的範例可以參考底下的教材與練習: dsPIC30F Module Training - I2C 教材及練習 http://www.microchip.com.tw/modules/mydownloads/viewcat.php?cid=4
發表於: 2008/4/3 15:32
|
|||
|
dsPIC30F2010 I2C 使用問題
|
||||
---|---|---|---|---|
新會員
|
手上有2顆dsPIC30F2010,
1顆做I2C Master 使用, 1顆做Slave使用. 做 Master 寫資料到 Slave 的動作 OK! 但 Master 要讀 Slave 資料時, 就無法執行! 目前只做傳送1Byte資料, I2CCONbits.ACKEN=1, Master/Slave動作如下: Master 送位址及R/W_bit=1, 等待確認... Slave 接收後, 讀出位址並送Ack_bit !! Master 確認Ack_bit後, I2CCONbits.RCEN=1, 等待接收... Slave 將資料載入I2CTRN, I2CCONbits.SCLREL=1, 釋放 SCL_Line!! 此時, 問題發生了!!!!!!!!!!!! 示波器放完全沒有Master送出的Clock.... Slave也無法送出Data...... 請問, 我還有什麼沒有設定到的??? 謝謝!!!!
發表於: 2008/4/2 14:42
|
|||
|