您的位置 首页 厂商

STM32中CAN过错中止1

voidcan_signal(void){unsignedchardatacan_irq;unsignedchardatatemp;x_wdgtime();can_irq=InterruptReg;i

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;
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/260502.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部