s23k144 CAN_ESR1 is not working properly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

s23k144 CAN_ESR1 is not working properly

3,342 Views
shingozhou
Contributor III

Hi,

I make the two CAN wires (CAN_High and CAN_Low) short curcuit without sending any frame to MCU. Call the lib function FLEXCAN_DRV_Init(INST_CAN0COM, ...) and read the CAN_ESR1, the value of CAN_ESR1 is 0x280036 at the first time . and then, I call the FLEXCAN_DRV_Deinit(INST_CAN0COM) ,FLEXCAN_DRV_Init(INST_CAN0COM, ...) and read the CAN_ESR1 again, the value of CAN_ESR1 become 0x40080. It keep this value  all the time, even though separete the two CAN wires.

So, could the CAN_ESR1 report the real CAN status in time?

Here is my gold: detect the CAN status whether normal or bus-off.  send the standard frame if normal status,  otherwise call the FLEXCAN_DRV_Init to initialize the CAN and detect the status again till entering normal status , record the number of entering bus-off status.

But the CAN_ESR1 could not report the real status in time, How to achieve this target?

BR,

shingo

0 Kudos
Reply
8 Replies

2,559 Views
alexandrunan
NXP Employee
NXP Employee

Hello,

You can detect the error of bus-off by enable the error report IRQ by installing a error callback:

<p>/* declaration of callback function */ </p>
<p>void flexcan_error_callback(uint8_t instance, flexcan_event_type_t eventType, flexcan_state_t *flexcanState)<br />{<br />/* Your code Here */<br />}</p>
<p>/* Install of callback */</p>
<p>FLEXCAN_DRV_InstallErrorCallback(INST_CANCOM1, flexcan_error_callback, NULL);</p>

and you can use the function:

 FLEXCAN_DRV_GetErrorStatus(INST_CANCOM1); that returns the value of ESR1

0 Kudos
Reply

2,559 Views
shingozhou
Contributor III

Hi,Alexandru Nan:

I could not find these functions "FLEXCAN_DRV_GetErrorStatus( )" and "FLEXCAN_DRV_InstallErrorCallback( )" in S32SDK_S32K14x_EAR_0.8.6 and 0.8.4.
Where are these functions?

BR,

shingo

0 Kudos
Reply

2,559 Views
alexandrunan
NXP Employee
NXP Employee

This functions can be found in last release for S32k144 which is S32K14x BETA 1.9.0 available here

S32 Design Studio IDE for Arm® based MCUs|NXP  

Them are available in CAN driver header file and doxy manual.

BR,

Alex Nan

0 Kudos
Reply

2,559 Views
shingozhou
Contributor III

Alex Nan:

Thank you for your help firstly!

I found this function finally. It returns the value of CAN_ESR1, but now, the question is that: the value when entering the bus-off status is difference between at the first time and at the other time.

when the bus-off occured , the value of CAN_ESR1 was correct and going to ISR. when the bus-off occured again, the value was wrong  and not going to the ISR.

It seems the CAN_ESR1 could not report the real CAN bus status in time.

BR,

shingo

0 Kudos
Reply

2,559 Views
alexandrunan
NXP Employee
NXP Employee

The difference of the CAN_ESR register values can appear because of the mode of handling of interrupt causes, be aware that interrupt can be generated by multiple sources. Every source need to be handle differently. Can you share the values of ESR to check which are causing errors ?! 

0 Kudos
Reply

2,559 Views
shingozhou
Contributor III

Alex Nan:

   I have set CAN_CTRL1[BOFFREC] = 1(automatic recovering from Bus Off state disabled), and enable bus-off interrupt.

Made the two CAN wires (CAN_High and CAN_Low) short curcuit all the time, in other words, the CAN keep bus-off status all the time in theory.

Program starts running. The CAN_ESR1 value is 0x280036 at the first time and going to execute the ISR, the ESR1 value becomes 0x280030 after ISR finished. Then I call the FLEXCAN_DRV_Deinit(INST_CAN0COM,..) ,FLEXCAN_DRV_Init(INST_CAN0COM, ...) to initialize CAN peripheral of S32K144 mcu. But it doesn't execute the ISR, I read the CAN_ESR1 again, the CAN_ESR1 value becomes 0x00040080.I think that the ESR1 value is 0x280036 and going to execute the ISR again.

What do you think?

BR,

shingo

0 Kudos
Reply

2,559 Views
alexandrunan
NXP Employee
NXP Employee

When you read the ESR1 register some flags are cleared automatically according to RM, this is way you never have the same value if you read consecutive the ESR1 register. I believe the ISR for bus-off is executed in your case only once because the bus never return in (idle)normal state. 

So try to return the bus in normal state and then cause again the bus-off condition by creating short circuit on the lines, I expect this time to trigger again the bus-off state and the ISR. 

0 Kudos
Reply

2,559 Views
shingozhou
Contributor III

Alex Nan:

In brief, Made the two CAN wires (CAN_High and CAN_Low) short curcuit all the time.

I Call the FLEXCAN_DRV_Init(INST_CAN0COM, ...) and trigger the bus-off state and the ISR. And then I call the FLEXCAN_DRV_Init(INST_CAN0COM, ...)  again, It does not trigger the bus-off state or the ISR.

Why the two results are different?

0 Kudos
Reply