×
单片机 > 单片机程序设计 > 详情

STM32中CAN错误中断1

发布时间:2020-09-03 发布时间:
|
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;
}

关键字:STM32 CAN 错误中断 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
MSP430F5529 上手小例程2