CAN Error Frame Register

maxdog

New member
I am working on a project that counts total CAN bus error frames, as well as monitor bus load in real time using a Teensy4.0

How can I access the values in the CAN Rx Error registers? I found them in the iMXRT manual, I am just not sure how to read them.

My plan was to continuously check the value of the error counter in a loop, and if it was greater than the last loop, it would add the difference. Unless somebody knows of a better way.

As far as bus load, assuming all 29bit IDs, would it be as simple as counting the (number of messages in a second x 29) / bit rate ?

The data points don't need to produce absolutely perfect results, It is just going to be used to detect when bus conditions are less ideal than average.

Any input would be greatly appreciated!
 
With the FlexCAN_T4.h library you can call the error(CAN_error_t &error, bool printDetails) function.
This will give you these type of errors:
Code:
typedef struct CAN_error_t {
  char state[30] = "Idle";
  bool BIT1_ERR = 0;
  bool BIT0_ERR = 0;
  bool ACK_ERR = 0;
  bool CRC_ERR = 0;
  bool FRM_ERR = 0;
  bool STF_ERR = 0;
  bool TX_WRN = 0;
  bool RX_WRN = 0;
  char FLT_CONF[14] = { 0 };
  uint8_t RX_ERR_COUNTER = 0;
  uint8_t TX_ERR_COUNTER = 0;
  uint32_t ESR1 = 0;
  uint16_t ECR = 0;
} CAN_error_t;

Set the printDetails to 1, it will print the error out on the serial port.

Example, call this at regular interval:

Code:
  CAN_error_t can_error;
  can1.error(can_error, 1);

You will see results like this:
AN State: Receiving, CRC_ERR, STF_ERR, FLT_CONF: Error Active
FlexCAN State: Receiving, FLT_CONF: Error Active
FlexCAN State: Receiving, CRC_ERR, STF_ERR, FLT_CONF: Error Active
FlexCAN State: Receiving, FLT_CONF: Error Active
FlexCAN State: Transmitting, FLT_CONF: Error Active

STF_ERR is a Stuff bit error
CRC_ERR is a CRC bit error

Tested with PCAN-View on a PCAN-USB Pro FD analyser.
192_168_1_28.jpg
 
Last edited:
Back
Top