Description

b_autorecover – controls the behaviour in cases of bus failures (e.g. bus-off state)
If true then the CAN bus will try to re-start the interface each time sendMsgBuf(), setMode() or transmitBufferFull() is called.
If false then the application would have to discover the failure by itself and has to trigger a restart by calling reenable() or setMode().

#defines

  • FILTER_0FILTER_7 – used for filter settings of standard ID filters
  • FILTER_EXT_0FILTER_EXT_7– used for filter settings of extended (29bit) ID filters
  • MSG_ID_ALLOW_ALL_MASK – used in init_FiltID() to receive all std. or all ext. IDs
  • CAN_OK, CAN_FAILINIT, CAN_FAILTX, CAN_NOMSG, CAN_CTRLERROR and CAN_FAIL – function return values
  • MCP_NORMAL, MCP_LISTENONLY – operation mode used in setMode()
  • CAN_FILTER_RANGE, CAN_FILTER_CLASSIC – return values of getFilterType()

Syntax

MCAN0.b_autorecover = true;

Parameters

none

Returns

nothing

Example Code

The following example switches the b_autorecover function of, send msg., checks and re-enables the bus in case of a bus failure.

void setup()
{
	while(!Serial);
	Serial.println("Check the bus state of CAN0");
	
	// disable the autorecover feature
	MCAN0.b_autorecover = false;
	Serial.println("Now cause some bus failure (e.g. CANH/L short circuit)");
}
void loop()
{
	// Send CAN messages
	CANMessage myMsg;
	myMsg.id = 0x12345;
	myMsg.ext = true;
	myMsg.len = 1;
	myMsg.data[0] = 0xA5;
	MCAN0.sendMsgBuf(myMsg); 
	delay(100);
	// Check the Bus state
	if(MCAN0.isEnabled())
	{
		//Bus failure! restarting the bus
		digitalWrite(LED_BUILTIN, HIGH); 
		MCAN0.reenable();
	}
	else
		digitalWrite(LED_BUILTIN, LOW);
}

Notes and Warnings

Be aware of the b_autorecover setting. It might be handy to have it enabled for cases of temporary failures on the can bus. The device would automatically get back into operation on the CAN bus afterwards. Still, in other cases e.g. if the device operates at a different baud rate than the remaining nodes, this would rather lead to a persistent blocking of the bus traffic.
b_autorecover is true by default. The bus state can be supervised by isEnabled()

Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> CAN Bus ->

See also

Find more details about the the CAN bus of dice devices
sendMsgBuf()
transmitBufferFull()
setMode()
isEnabled()
reenable()
SAMC21_CAN – Library
CAN operation background
users manual
BOOTLOADER SETTINGS – Library
samc21 datasheet