Re: 求救!!!關於PIC18F4525,I2C Slave Mode問題。
|
||||
---|---|---|---|---|
版主
|
建議你先看一下 Microchip I2C EEPROM 的規格 24LC02B 了解一下Sequential R/W and Random R/W 的命令。
http://www.microchip.com/stellent/idc ... Id=1335&dDocName=en010810 右邊再範例程式下的12.1 有Master的範例參考一下 Master 的命令 : http://www.microchip.com.tw/example.htm
發表於: 2008/1/14 21:01
|
|||
|
Re: 求救!!!關於PIC18F4525,I2C Slave Mode問題。
|
||||
---|---|---|---|---|
新會員
|
十二萬分的感謝您~~~可以讀寫了...
但是...I2C_Index會被清掉,Sequential Read/Write,不知該怎做?? 謝謝樓上大大快速的回覆!!! 再次拜託了!!
發表於: 2008/1/14 17:23
|
|||
|
Re: 求救!!!關於PIC18F4525,I2C Slave Mode問題。
|
||||
---|---|---|---|---|
版主
|
現在的作法是 : PIC18F & 16-bit 系列的範例幾乎都是使用 C 來寫。PIC16F 系列因為 Microchip 並沒有出自己的 C compiler 所以會以 assembly 為主。
發表於: 2008/1/11 16:17
|
|||
|
Re: 求救!!!關於PIC18F4525,I2C Slave Mode問題。
|
||||
---|---|---|---|---|
版主
|
Calvin 已經將 I2C Master & Slave 的範例放上去了。
http://www.microchip.com.tw/modules/wfdownloads/viewcat.php?cid=12
發表於: 2008/1/11 14:23
|
|||
|
Re: 求救!!!關於PIC18F4525,I2C Slave Mode問題。
|
||||
---|---|---|---|---|
版主
|
待會會請 Calvin 將他寫的 I2C Master & Slave 的範例放在下載中心裡的範例程式哩,此範例使用 APP001及PIC18F4520
發表於: 2008/1/11 14:02
|
|||
|
Re: 求救!!!關於PIC18F4525,I2C Slave Mode問題。
|
||||
---|---|---|---|---|
高級會員
|
void write_i2c(unsigned char data)這函數裡,在while(SSPSTATbits.BF){} 之前,先對SSPBUF做讀取看看,因為有可能SSPBUF已經被SLAVE ADDRESS佔住了,所以你是無法將你要回給MASTER的DATA寫進去!
發表於: 2008/1/11 13:59
|
|||
|
求救!!!關於PIC18F4525,I2C Slave Mode問題。
|
||||
---|---|---|---|---|
新會員
|
原先參考 AN743,但一直有Read 錯誤,後來於Microchip 英文討論版看到,AN743有些問題,但是還是無解,不知有哪位大大能幫幫我解決~~~
請參考以下中斷程式: unsigned char temp = SSPSTAT & 0b00101101; // Mask out unimportant bits in SSPSTAT switch (temp) { // State 1: Write operation, last byte was an address, buffer is full. case ( 0b00001001 ): // clear receive buffer index = 0; // Clear the buffer index read_i2c(); // Do a dummy read of SSPBUF break; // State 2: Write operation, last byte was data, buffer is full. case ( 0b00101001 ): receivedBuffer[index++] = read_i2c(); if(index==64) index = 0; break; // State 3: Read operation, last byte was an address, buffer is full. case ( 0b00001101 ): write_i2c(writeData); break; // State 4: Read operation, last byte was data, buffer is empty. case ( 0b00101100 ): write_i2c(writeData); break; default: break; } } } void write_i2c(unsigned char data){ while(SSPSTATbits.BF){} // Wait until buffer is empty do{ SSPCONbits.WCOL = 0; // Clear WCOL flag SSPBUF = data; // Write the data to the buffer } while ( SSPCONbits.WCOL ); // Loop when there's a write collision SSPCONbits.CKP = 1 // Release the clock } unsigned char read_i2c(){ return SSPBUF; } State 4有時進不去...Master可以讀取第一筆(Byte),但第二筆(Byte)就再也無回應了... 以上拜託了!!謝謝!!
發表於: 2008/1/11 13:24
|
|||
|