之前做发送的时候,中断都没问题的,可以正常发送,现在做接收程序,老是进入红 {MOD}部分,所以无法接收数据,不知道有没有人碰到类似的情况。
//*****************************************************************************
// CAN中断服务函数
//*****************************************************************************
void
CANIntHandler(void)
{
unsigned long ulStatus;
// Read the CAN interrupt status to find the cause of the interrupt
ulStatus = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);//控制器中断寄存器的值并表示中断产生的原因
// If the cause is a controller status interrupt, then get the status
if(ulStatus == CAN_INT_INTID_STATUS)//中断产生的原因是一个状态中断
{
//在读取主控制器状态寄存器时,将清除一个正詆诠移鸬淖刺?卸?
g_bErrFlag = 1;// 表示有错误发生
}
else if(ulStatus == 1)//表示具有高优先级编号1的报文对象正在挂起一个中断
{
CANIntClear(CAN0_BASE, 1);//清除报文对象中断
g_ulMsgCount++;//中断次数递增,记录接收到报文的数目
g_bRXFlag = 1;//已接收一条报文
g_bErrFlag = 0;//清除错误标记
}
else//其他不可预知的原因导致中断,这将永远不会发生
{
// Spurious interrupt handling can go here.
}
}
此帖出自
小平头技术问答
//! the status register should be read with the CANStatusGet() function.
//! Calling this function to read the status also clears the status
//! interrupt. If the value of the interrupt register is in the range 1-32,
//! then this indicates the number of the highest priority message object that
//! has an interrupt pending. The message object interrupt can be cleared by
//! using the CANIntClear() function, or by reading the message using
//! CANMessageGet() in the case of a received message. The interrupt handler
//! can read the interrupt status again to make sure all pending interrupts are
//! cleared before returning from the interrupt.
应该调用一下 CANStatusGet() 来清除一下标记
一周热门 更多>