CAN (canbus)


CAN::errorStatus, errorStatus, CAN.errorStatus

Get the current error status of the CAN bus.

int status = can.errorStatus();

Returns: int CAN_NO_ERROR when everything is ok, CAN_ERROR_PASSIVE when not attempting to transmit messages but still acknowledging messages, CAN_BUS_OFF when not transmitting or acknowledging messages.

CANChannel can(CAN_D1_D2);
if(can.errorStatus() == CAN_BUS_OFF) {"Not properly connected to CAN bus");

This value is only updated when attempting to transmit messages.

The two most common causes of error are: being alone on the bus (such as when using a CAN shield not connected to anything) or using the wrong baud rate. Attempting to transmit in those situations will result in CAN_BUS_OFF.

Errors heal automatically when properly communicating with other microcontrollers on the CAN bus.