Skip to main content
SkyWork
Associate III
January 14, 2020
Question

How can i get CAN Error code

  • January 14, 2020
  • 2 replies
  • 991 views

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

This topic has been closed for replies.

2 replies

JoniS
Senior
January 14, 2020

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
SkyWorkAuthor
Associate III
January 14, 2020

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?