cancel
Showing results for 
Search instead for 
Did you mean: 

How can i get CAN Error code

SkyWork
Associate III

Dear

I use bxCAN new HAL library

I register notification by calling "HAL_CAN_ActivateNotification" and enable the following

CAN_IT_ERROR and CAN_IT_LAST_ERROR_CODE and CAN_IT_BUSOFF and CAN_IT_ERROR_PASSIVE and CAN_IT_ERROR_WARNING.

I'd implemented HAL_CAN_ErrorCallback this function

I'd try to do the following things

  1. connect CAN-H to ground
  2. connect CAN-H and CAN-L PIN

But there's no error notification happening ,

Is there anyone know how to produce CAN ERROR

Thanks

2 REPLIES 2
JoniS
Senior

I have not tested it, but atleast datasheet of my stm32f446re6 says

The LEC[2:0] bits can be set to value 0b111 by software. They are updated by hardware to indicate the current communication status. 
LEC bits are 4-7 from CAN_ESR register in my mcu.
CAN_ESR |= (111 << 4);

For you the bit positions might vary, but something like that should in my opinion trigger the interrupt.

SkyWork
Associate III

Dear JoinS

I using HAL_CAN_ActivateNotification (hcan, CAN_IT_LAST_ERROR_CODE) to set the LEC bit in IER register

May i know how you trigger CAN ERROR?