Bus-Off Handling in MSCAN

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bus-Off Handling in MSCAN

No ratings

Bus-Off Handling in MSCAN

Hello Community user,

This post is intended to show how to recovery from Bus-Off state using the MSCAN and CANPHY modules in the MagniV devices. This example is focused on S12ZVC due to the internal CANPHY so it makes easier to create a quick example.

What is Bus-Off condition?

The bus-off condition is a catastrophic condition where the node in this state does not transmit anything on the bus.

How to enter in Bus-Off state?

A node enters in this state if any of the two error counters, Transmit Error Counter (TEC) and Receive Error Counter (REC) raises above 255.

How to recovery from Bus-Off?

A note is permitted to become error-active (no longer bus-off) when its error counters both set to 0 after 128 occurrences of 11 consecutive recessive bits have been monitored on the bus. The MSCAN module implements two ways to recover from the fault, the automatic and the manual.

The automatic bus-off recovery method puts the node into the error-active state after monitoring 128 occurrences of 11 consecutive bits on the bus. It's important to note that the CANPHY also reports errors on the bus so, the proper error flags must be clear to assure the correct functionality of the node if CANPHY is being used.

The manual bus-off recovery method (which is used in this example) puts the note into the error-active state after both independent events have become true in any order:

  • 128 occurrences of 11 consecutive recessive bits on the CAN bus have been monitored. (Cannot be consecutive).
  • CANMISC[BOHOLD] bit has been cleared by the user.

Implementation

The project contains a header file called  "common.h" which contains three defines that are used to set the CAN nodes. Just one define must be active per node. NODE0_TX and NODE1_TX are transmitting messages on the CAN bus and the NODE_RX is receiving the messages.

#define NODE0_TX 
#define NODE1_TX
#define NODE_RX‍‍‍

All nodes are blinking the green led indicating the communication is stable and no errors have occurred. At this point, you should generate the bus-off condition. A way to generate a bus-off condition is grounding one of the two CAN lines (CAN_High or CAN_Low) which will cause a bus-off condition to the transmitters nodes. When the node is in the bus-off state, the yellow led is toggled. At this point, you should not be any message being transmitted on the bus due to the transmitter node is in bus-off. The bus-off condition is detected by the application in the bus-off interrupt (refers Events.c file) which triggers the yellow led toggling.

void CAN0_OnBusOff(void)
{
 /* Get CAN bus status */
 CAN0_GetError(&gCANErrpr);
 /* If bus error is set, inform to the application*/
 if(gCANErrpr.errName.BusOff){
 gBusOffState = PENDING;
 }
 CAN0RFLG_CSCIF = 1; // Clear flag
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In the main.c file when the node transmitters are selected, there is a routine asking for a push-button event. This event triggers the bus-off recovery request by setting the CANMISC[BOHOLD]. At that point, the 128 occurrences of 11 consecutive recessive bits on the CAN bus should have passed and the green led will toggle again indicating the communication is stable again and no errors have occurred. At this point, you should see the messages on the CAN bus again.

/* Read button to recovery from bus off condition*/
if(PushButton3_GetVal()){
 CAN0_BusOffRecoveryRequest(); // Request get out of bus off
 gBusOffState = NONPENDING;
 /* Clear bus off LED indicator */
 LED_YEL_OFF;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍
‍‍‍‍‍‍‍

Note:

The VLG-MC9S12ZVC was used for this example and the push button that must be pressed is SW12.

Best Regards,

Atzel Collazo

Labels (1)
Attachments
Version history
Last update:
‎09-10-2020 02:34 AM
Updated by: