Re: I2C 無法正確動作..
|
||||
---|---|---|---|---|
新會員
|
Mike 大大
我也遇到類似的問題 i2cread()得到的值為0xFF 在示波器上發現bq27200都不會回我ACK 不知道你有沒有遇過類似問題
發表於: 2009/10/28 9:51
|
|||
|
Re: I2C 無法正確動作..
|
||||
---|---|---|---|---|
初級會員
|
To All,
謝謝大大們的指教,我己經可以正確讀出 Battery 的相關數值 了, Thanks. Best Regards Mike
發表於: 2006/7/28 13:39
|
|||
|
Re: I2C 無法正確動作..
|
||||
---|---|---|---|---|
初級會員
|
感謝 powmien 大大:
我將試著用示波器來確認主控端的 SCL , SDA 的波形是否正確再一步步的除錯使雙方的 Protocol 可以 Match 讀值 ,謝謝 !!
發表於: 2006/7/20 13:22
|
|||
|
Re: I2C 無法正確動作..
|
||||
---|---|---|---|---|
高級會員
|
先跟slave 隔開,確定你的i2c scl sda 波形正常,再跟slave connect...
master scl sda 都為output, 接收ack時 sda 設成input start/stop bit 不算.. 一筆資料( 1 byte ) scl 會有九個pulse start bit 是 sda 先low 一段時間 scl 再low.. data sda 先hi scl 再hi , scl low sda 再low 這樣傳8 bits 接收ack/nak... stop bit scl先hi sda 再hi... over 大約這樣... 先確定波形ok...
發表於: 2006/7/19 17:01
|
|||
|
I2C 無法正確動作..
|
||||
---|---|---|---|---|
初級會員
|
版主您好:
小弟用18F452 的 RC3(SCL),RC4(SDA)與 外部 BATTERY (Bq27200) 的 SCL, SDA線路相接, 透過使用手冊的說明18F452其內部本身具有上升電阻,並且使用 I2C 的 MASTER 範例程式 來調試 I2C 的傳輸狀況(以LED秀出),但是我發現在傳送開始條件 (SSPCON2bits.SEN = 1;), 然後再判斷 PIR1bits.SSPIF 的回傳值是否成功,就永遠為 0 ,不知是何原因,以下為簡單的 Sample code list.. #include <p18cxxx.h> void main() { F_Initial(); F_I2C_START(); //卡住,無法進入下一行指令,並看見灯亮.. PORTD = 0XAA; if (F_I2C_Send_Address(I2C_Device1,UC_I2C_CMD)) ... } void F_Initial(void) { TRISD = 0; LATD = 0; TRISCbits.TRISC3 = 0; TRISCbits.TRISC4 = 0 ; SSPSTATbits.SMP = 1; SSPSTATbits.CKE = 0; SSPCON1 = 0x38; SSPADD = 0x30; } void F_I2C_START(void) { SSPCON2bits.SEN = 1; while(!F_I2C_WAIT()); //永遠等待,無法跳出迴圈 } unsigned char F_I2C_WAIT(void) { if ( PIR1bits.SSPIF ) { PIR1bits.SSPIF = 0; return (1); } else return (0); } 本程式為 PIC18Fxx2微控制器實習模組的I2C master 範例程式,但我皆無法在 START BIT 之後無法繼續下去,不知是否在外掛電池(Bq27200)與實驗板是否需要注意什麼事項,否則為何我皆無法正確動 作,謝謝大大的指教 !!
發表於: 2006/7/19 11:33
|
|||
|