cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 Enable Can Error Irq

Posted on October 16, 2015 at 17:19

Hello,

I would like to enable the CAN error Irq and in particular the LEC so in my init function I did

CAN_ITConfig( CAN2, CAN_IT_TME | CAN_IT_FMP0 | CAN_IT_FOV0 | CAN_IT_FF0 | CAN_IT_LEC | CAN_IT_ERR, ENABLE );

and then in the irq I did like that

void CAN2_StatusChangeError_IRQHandler( void )

{

   if (CAN_GetITStatus( CAN2, CAN_IT_LEC ) == SET )

   {

      HALCAN_ERROR_2ND_CAN(CAN_GetLastErrorCode(CAN2));

      CAN_ClearITPendingBit( CAN2, CAN_IT_LEC );

   }

}

In normal working everything goes fine but  if I remove the cable I continously go in the irq: I would like to go inside only once. Is there something I'm missing?

I configured it to automatically exit from bus off .. I don't know if that is the problem.

thank

michele

#can-stm32f407
4 REPLIES 4
jpeacock
Associate III
Posted on October 16, 2015 at 17:36

A disconnected CAN will continuously generate errors since there's no other node.  How you handle it is application and protocol dependent.  I disable the CAN bus for a short interval to stop the error flood, and then try again after the interval to see if it reconnects.

  Jack Peacock
Posted on October 19, 2015 at 12:05

Hello Jask,

thanks for your answer: I disabled the automatic exit from bus-off. I would expect that when it reaches the bus-off there is no more Irq, instead it continously goes in Irq. I would like to know as soon as possible if there is a bus-off but it seems to me very tricky to have to disable the irq and then re-enable it after periodically .. is there a better way?

thanks for the  support
jpeacock
Associate III
Posted on October 19, 2015 at 14:23

A bus off event along with excessive errors (EPV, REC, TEC) tells you there is a bus fault.  Bus off is a symptom, not a cause so disabling it won't change anything.  The IRQs are doing what they are supposed to do, report bus faults. 

Use the CAN SCE interrupt to catch the error conditions as soon as possible.  After that you have to switch the CAN bus to SILENT mode (BTR register) and turn off the SCE interrupt to ignore errors.  Clear the errors before restarting the bus.

Typically this type of fault is only a startup condition, before any other nodes are active.

So once your network is up you don't have to constantly disable the bus to clear it.  Periodically retrying the bus has worked well for me so I haven't looked for any other way (and no other path is obvious).

  Jack Peacock

Posted on October 19, 2015 at 15:14

Thanks for your feedback,

I will check the best way to do.

Michele