Re: PIC18F4550 I2C 的address 問題___part 2
|
||||
---|---|---|---|---|
初級會員
|
版主大大
請問有void Initialize_I2C_Slave(void) 裡頭OpenI2C(SLAVE_7,SLEW_ON); 的程式嗎? 因為看不到OpenI2C(SLAVE_7,SLEW_ON) 函式的內容ㄝ 謝謝
發表於: 2007/11/29 11:45
|
|||
|
Re: PIC18F4550 I2C 的address 問題___part 2
|
||||
---|---|---|---|---|
版主
|
直接 copy 一段 何仁杰 先生寫的 I2C Slave 程式,參考依下:
#include <p18f4520.h>
發表於: 2007/11/28 8:27
|
|||
|
Re: PIC18F4550 I2C 的address 問題___part 2
|
||||
---|---|---|---|---|
初級會員
|
這是slaver 的設定程式
LATBbits.LATB0 = 0; // initial Latch of PORTB LATBbits.LATB1 = 0; // initial Latch of PORTB TRISBbits.TRISB0 = 1; // set RB0/SDA as input pin. TRISBbits.TRISB1 = 1; // set RB1/SCL as input pin. SSPCON1=0b00100110; // SSPADD=0x02; // Address = 0x02 SSPCON2bits.GCEN=1; RCONbits.IPEN=1; INTCONbits.GIEH=1; //enable ALL high priority interrupts INTCONbits.GIEL=1; INTCON2bits.TMR0IP=1; //TMR0 is high priority PIE1bits.SSPIE=1; //enable the MSSP interrupt IPR1bits.SSPIP=0; //MSSP interrupt low priority T0CON=0b00000000; //bit7:enable TMR0H=0b11101000; TMR0L=0b10001111; INTCONbits.TMR0IE=1; 這是slaver的中斷副程式 void I2C_interrupt () { unsigned char temp; int i; if(PIR1bits.SSPIF==1) //如果I2C中斷發生 { PIR1bits.SSPIF=0; temp=SSPBUF; if(temp == 0x02) { TRISDbits.TRISD1=0; PORTDbits.RD1=1; } } } 這是 master 的設定程式 LATBbits.LATB0 = 1; // initial Latch of PORTB LATBbits.LATB1 = 1; // initial Latch of PORTB TRISBbits.TRISB0 = 1; // set RB0/SDA as input pin. TRISBbits.TRISB1 = 1; // set RB1/SCL as input pin. SSPADD=0xe; //clock = 400kHZ SSPCON1=0b00111000; SSPCON2bits.GCEN=1; SSPSTAT=0b00000000; 這是master send I2C 給slave(0x02)的程式 , 只是slaver沒ack, 也就是沒回應 , 沒產生中斷 , 不過送0x00就會中斷 I2C_START(); if (I2C_Send_Address(0x02)) { I2C_STOP(); } else{ I2C_Send_Data(0x66); I2C_STOP(); }
發表於: 2007/11/27 23:17
|
|||
|
Re: PIC18F4550 I2C 的address 問題___part 2
|
||||
---|---|---|---|---|
資深會員
|
我想可檢查以下幾點
PIE1<SSPIE> 要設為 1 SSPCON1<SSPM3:SSPM0> 跟 start/stop bit 中斷有關 GCEN 是用在當有 address 0 的訊號時用的 若沒用應設為 0 還有 SSPIF 要設為 0, 中斷後也要還原為 0 (clear) 或許把你的程式 post 出來, 要不很難知道...
發表於: 2007/11/23 16:32
|
|||
|
Re: PIC18F4550 I2C 的address 問題___part 2
|
||||
---|---|---|---|---|
版主
|
PIC18F4550 已經量產很久了,查了一下 Silicon B5 版本的 Errata 也沒有相關的I2C Slave 問題,所以我個人認為還是要找一下程式的 Bug。
發表於: 2007/11/21 14:57
|
|||
|
PIC18F4550 I2C 的address 問題___part 2
|
||||
---|---|---|---|---|
初級會員
|
Dear 大大
雖然我的slaver PIC的SSPADD設0x02 , SSPCON2的GCEN設1, 但我的master PIC的I2C 第一個byte(address) 從1送到255 , slaver PIC也不會有中斷發生 , 只有address送0x00 , slaver PIC才發生中斷 . . . . . . 這是PIC的問題嗎??????
發表於: 2007/11/19 22:42
|
|||
|