新闻中心

EEPW首页>嵌入式系统>设计应用> STM32中CAN错误中断1

STM32中CAN错误中断1

作者: 时间:2016-11-24 来源:网络 收藏
void can_signal(void)
{
unsigned char data can_irq;
unsigned char data temp;
x_wdgtime();
can_irq = InterruptReg;
if(can_irq&ALI_Bit)
{ // 仲裁丢失位
++al_counter;
temp=ArbLostCapReg; // 读仲裁丢失寄存器
alc_current=temp&0x1F; // 获得当前仲裁丢失的位置
}
if(can_irq & BEI_Bit)
{ // 总线 错误中断
temp=ErrCodeCapReg;
buse_current=temp&0x3F;
temp=temp&0xD0; // 获得总线错误的类型
switch (temp)
{
case 0x00: ++bite_counter;
case 0x40: ++forme_counter;
case 0x80: ++stuffe_counter;
case 0xd0: ++othere_counter;
}
}
if(can_irq & EPI_Bit)
{ // 消极错误中断,
// 接收或发送错误计数超过127时,错误状态变为被动错误
if((RxErrCountReg>127)||(TxErrCountReg>127)) errstatus_current=ERR_PASSIVE;
// 接收或发送错误计数回到小于127时,错误状态变为主动错误
if((RxErrCountReg<127)&&(TxErrCountReg<127)) errstatus_current=ERR_ACTIVE;
}
if(can_irq & DOI_Bit)
{ // data overflow
CommandReg = (CDO_Bit|RRB_Bit);
return;
}
if(can_irq&EI_Bit)
{ // 错误报警中断, 这里只对总线关闭错误做处理
if(StatusReg&BS_Bit)
{ // 检测状态寄存器的总线状态位
++busoff_counter;
ModeControlReg = 0x00;
return;
}
}
if(can_irq & RI_Bit)
{ // 接收数据中断
if(StatusReg & DOS_Bit)
{
CommandReg = (CDO_Bit|RRB_Bit);
return;
}
can_readmsg();
return;
}
return;
}



关键词:STM32CAN错误中

评论


技术专区

关闭