CAN Busoff Recovery problems

Iam now use S12ZVC ,theproblem is when Busoff happened the MSCAN could generate a CANerror interrupt .when busoff selfrecovery MSCAN will generate an CANerror interrupt then. The MCU will enter a cycle :busoff happened 、recovery、busoff happened 、recovery

Your code contains CAN0CTL1_BORM=0; command. That means that only way how the MSCAN module may leave the bus-off state is when the module detects 128 occurrences of 11 consecutive recessive bits.

If you want to use CAN bus-off recovery upon user request (CAN0MISC_BOHOLD = 0x01;), you have to enable that feature by setting BORM bit in a CANCTL1 register.

According to your second thread, you want to use stop mode. I would like to recommend switch MSCAN module into sleep mode prior entering to MCU stop mode. This will prevent against generating error frames on the CAN bus due to unexpected stop mode.

Please use commands below prior entering into stop mode.

CAN0CTL0_SLPRQ = 1; //sleep mode request

while(CAN0CTL1_SLPAK == 0); //wait for acknowledge of sleep mode

This will manage that MCU will finish all scheduled frames in TX buffers and waits until receiving frame ends (it wait for bus idle).

I tried my code again .if I set CAN0CTL1_BORM=0; the MSCAN leave the bus-off state is when the module detects 128 occurrences of 11 consecutive recessive bits.Then it will enter busoff again

If I set CAN0CTL1_BORM=1;the MSCAN will leave the bus-off state is when(CAN0MISC_BOHOLD = 0x01;）initialize MSCAN. and the module detects 128 occurrences of 11 consecutive recessive bits. But it will enter Busoff again .Leave the Busoff enter the Busoff