新聞中心

STM32中CAN錯(cuò)誤中斷1

作者: 時(shí)間:2016-11-24 來(lái)源:網(wǎng)絡(luò) 收藏
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; // 獲得當(dāng)前仲裁丟失的位置
}
if(can_irq & BEI_Bit)
{ // 總線錯(cuò)誤中斷
temp=ErrCodeCapReg;
buse_current=temp&0x3F;
temp=temp&0xD0; // 獲得總線錯(cuò)誤的類型
switch (temp)
{
case 0x00: ++bite_counter;
case 0x40: ++forme_counter;
case 0x80: ++stuffe_counter;
case 0xd0: ++othere_counter;
}
}
if(can_irq & EPI_Bit)
{ // 消極錯(cuò)誤中斷,
// 接收或發(fā)送錯(cuò)誤計(jì)數(shù)超過(guò)127時(shí),錯(cuò)誤狀態(tài)變?yōu)楸粍?dòng)錯(cuò)誤
if((RxErrCountReg>127)||(TxErrCountReg>127)) errstatus_current=ERR_PASSIVE;
// 接收或發(fā)送錯(cuò)誤計(jì)數(shù)回到小于127時(shí),錯(cuò)誤狀態(tài)變?yōu)橹鲃?dòng)錯(cuò)誤
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)
{ // 錯(cuò)誤報(bào)警中斷, 這里只對(duì)總線關(guān)閉錯(cuò)誤做處理
if(StatusReg&BS_Bit)
{ // 檢測(cè)狀態(tài)寄存器的總線狀態(tài)位
++busoff_counter;
ModeControlReg = 0x00;
return;
}
}
if(can_irq & RI_Bit)
{ // 接收數(shù)據(jù)中斷
if(StatusReg & DOS_Bit)
{
CommandReg = (CDO_Bit|RRB_Bit);
return;
}
can_readmsg();
return;
}
return;
}



關(guān)鍵詞: STM32CAN錯(cuò)誤中

評(píng)論


技術(shù)專區(qū)

關(guān)閉