INTERRUPT_HANDLER(I2C_IRQHandler, 19)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
if(I2C->SR2)
{
I2C->SR2 = 0;
}
if(I2C_GetITStatus(I2C_ITPENDINGBIT_STARTDETECTION))
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_STARTDETECTION);
IIC_Receive_event = 1; //START
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_STOPDETECTION))
{
////I2C_ClearITPendingBit(I2C_ITPENDINGBIT_STOPDETECTION);
IIC_Receive_event = 3; //STOP
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_RXNOTEMPTY))
{
//// I2C_ClearITPendingBit(I2C_ITPENDINGBIT_RXNOTEMPTY);
IIC_Receive_data = I2C_ReceiveData();
IIC_Receive_event = 2; //接收到数据
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_TXEMPTY))
{
////I2C_ClearITPendingBit(I2C_ITPENDINGBIT_TXEMPTY);
IIC_Receive_event = 4; //发送寄存器空
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_TRANSFERFINISHED)) //发送完成
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_TRANSFERFINISHED);
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_HEADERSENT)) //发送完成
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_HEADERSENT); //10-bit Header sent
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ADDRESSSENTMATCHED)) //地址发送完成/匹配
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ADDRESSSENTMATCHED);
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_WAKEUPFROMHALT)) //唤醒
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_WAKEUPFROMHALT);
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_OVERRUNUNDERRUN)) //Overrun/Underrun
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_OVERRUNUNDERRUN);
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE)) //确认失败
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE);
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_ARBITRATIONLOSS)) //!< Arbitration Loss
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ARBITRATIONLOSS);
}
else if(I2C_GetITStatus(I2C_ITPENDINGBIT_BUSERROR)) //Misplaced Start or Stop condition
{
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_BUSERROR);
}
else
{
nop();
}
}
我所有的中断事件都列举出来了,还是会一直进入中断,nop()这个位置。 出来后又进,崩溃了。
初始化如下
I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_ERR |I2C_IT_EVT|I2C_IT_BUF),ENABLE);
I2C_Init(100000,0X51,I2C_DUTYCYCLE_2,I2C_ACK_CURR,I2C_ADDMODE_7BIT,CLK_GetClockFreq());
I2C_Cmd(ENABLE);
请指点,谢谢大家 |