When the transmit error counters exceeds the the value 255, then CAN goes to Bus Off State. It stays in this state, until the Bus Off recovery sequence is finished, which is 128 bus idle conditions (11 recessive bits). After the recovery, module goes to error active state and once again it tries to re transmit the message. If the error condition does not exist on the bus anymore, the message will be transmitted successfully. If the error condition is still present on the bus,then once again the error counters starts to increment and module goes to bus passive and then to bus off state again. If you want to avoid the Bus Off recovery sequence and want to start the transmission immediately, then the user can opt for changing the mode to Configuration mode. In this case the error counters get cleared immediately. All the register contents will be preserved, even the interrupt flags remain unchanged. So, the user does not have to reinitialize all ECAN registers.
void clear_CanBusError(void) { //Enter configuration mode C1CTRL1bits.REQOP = CAN_CONFIGURATION_MODE; // Wait till desired mode is set. while( C1CTRL1bits.OPMODE != CAN_CONFIGURATION_MODE ); C1CTRL1bits.WIN = 1; C1RXF0SID = CAN_FILTERMASK2REG_SID((d_deviceAddr + d_gateWay)); C1RXF0SID = CAN_FILTERSTD(C1RXF0SID); C1CTRL1bits.WIN = 0; // Back to operation mode C1CTRL1bits.REQOP = CAN_NORMAL_OPERATION_MODE; // Wait till desired mode is set. while( C1CTRL1bits.OPMODE != CAN_NORMAL_OPERATION_MODE ); }