本帖最后由 chenzhi658 于 2017-7-10 08:49 编辑
问题:
1.每次总线离线,周期函数CAN_ERROR_CHECK没有检测到;
2.总线离线条件恢复总线正常条件,总线还是处于离线态;
解决:
1.CANNES寄存器对错误状态有锁存功能,一个错误发生,只有清除该错误,然后另一个错误才会被检测到;
2.总线离线后,要么初始化选择了CANMC.BIT.ABO=1自动重连自动恢复;要么CANMC.BIT.CCR=1唤醒总线;
void CAN_ERROR_CHECK(void)
{
static Uint16 CanBus_Reboot=0;
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
if(CanBus_Reboot==1){
if(ECanbShadow.CANES.bit.CCE == 1){
EALLOW;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
CanBus_Reboot=0;
}
}
if(ECanbShadow.CANES.bit.BO) // the can bus communicate error
{
ECanbShadow.CANES.bit.BO =1;
ECanbRegs.CANES.all = ECanbShadow.CANES.all;
EALLOW;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
CanBus_Reboot=1;
SystemSetError();
}
else if(ECanbShadow.CANES.all & 0x01bb0000){//除了离线错误,其他发生后马上清除
ECanbShadow.CANES.all = 0x01bb0000;
ECanbRegs.CANES.all = ECanbShadow.CANES.all;
}
}
|