#21ic问答#
附上I2C 从中断接收,初始化和中断函数。
现在问题无法接收到数据,是I2C设置问题或是没有进入中断?请教高手
本人用的是,PIC16F15224-CNANO 开发板
void iic_int(void)
{
SSP1DATPPS = 0x0C; //RB4->MSSP1:SDA1;
SSP1CL**S = 0x0E; //RB6->MSSP1:SCL1;
RB4PPS = 0x08; //RB4->MSSP1:SDA1;
RB6PPS = 0x07; //RB6->MSSP1:SCL1;
TRISB4 = 1;
TRISB6 = 1;
SSPM0 = 0;
SSPM1 = 1;
SSPM2 = 1;
SSPM3 = 0; // I2C slave mode ,7bit address
CKP = 1; // enable clock
SSPEN=1; //enable I2c
SSP1ADD = slaveAddress; // Load slave address
SSP1STAT=0x80;
PIE1bits.SSP1IE = 1; //Enabe interrupt MSSP
INTCONbits.PEIE = 1; // 启动外部中断
INTCONbits.GIE = 1; // 启动外部中断
}
void __interrupt() I2C (void)
{
if(SSP1IE && SSP1IF)
{
data = SSP1BUF;
addr(data);
}
SSP1IF=0;
} |