LPC54608 can bus off and can bus disconnected detection

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

LPC54608 can bus off and can bus disconnected detection

2,587 Views
cybaluke
Contributor III

Hi, I'm working with CAN periph. on a LPC54608.

I started from the example code "mcan_interrupt_transfer" from SDK with the OM13092 evb, I use the TJA1050T external transceiver and my code seems to works right.

I'm using the callback function as in the example code:

static void mcan_callback(CAN_Type *base, mcan_handle_t *handle, status_t status, uint32_t result, void *userData)

{

}

and I use the

   MCAN_TransferSendNonBlocking(VSCP_MCAN, &mcanHandle, &txXfer);

and

   MCAN_TransferReceiveFifoNonBlocking(VSCP_MCAN, 0, &mcanHandle, &rxXfer);

functions to write to and read from CAN bus, tha code seems to work fine but now I need some help to solve 2 problems:

1 - how can I detect the BUS_OFF condition in the mcan_callback function?
2 - when there are NO nodes connected in the bus (i.e. when the tranceiver is not conneced on can bus)  the code hangs in the while loop after the MCAN_TransferSendNonBlocking waiting the write completion:

      MCAN_TransferSendNonBlocking(VSCP_MCAN, &mcanHandle, &txXfer);

      while (!txComplete){ }   //<--it hanhs here...

      ... do something...

How can I detect when the bus is not connected to the tranceiver or how can I detect an error on the tranceiver?

I tried to catch the kStatus_MCAN_UnHandled condition in the  mcan_callback function but it seems to be detected only when the tranceiver works right,  but if it doesn't work right (for example the termination is broken) the condition kStatus_MCAN_UnHandled  dosn't work...  Is it possible to set a timeout for the CAN controller?

thanks for any suggestion...

Labels (4)
5 Replies

1,984 Views
cuixiaoming
Contributor I

Dear all,

    Now I don't know how to solve the problem of the CAN bus ErrorPassive too.

0 Kudos

1,984 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi cybaluke,

    Answer your two questions:

functions to write to and read from CAN bus, tha code seems to work fine but now I need some help to solve 2 problems:

1 - how can I detect the BUS_OFF condition in the mcan_callback function?

  Answer: Actually, you detect the bus off status in the according register PSR[BO], if the BO is 1, it means the CAN is in can bus off mode. you need to do the can bus off recovery process, the detail information you can refer to the content in the user manual:

pastedImage_1.png


2 - when there are NO nodes connected in the bus (i.e. when the tranceiver is not conneced on can bus)  the code hangs in the while loop after the MCAN_TransferSendNonBlocking waiting the write completion:

Answer: If there No nodes in the CAN bus, you send the can data, you will meet the problems, you also can detect the errors in the register:

pastedImage_2.png

Actually, before you send the CAN data, you must make sure your external hardware CAN tranceiver is connected, other wise the the status register will report the error code.

Wish it helps you!

If you still have question about it, please kindly let me know.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,984 Views
cybaluke
Contributor III

Thanks Kerry Zhou for your answer, it was helpful for me.

Do you also know if there is any sample code or public project for nxp micros where is managed the CAN bus bus-off condition and the other errors on the bus as a good starting point to for a CAN bus stack development (I don't need to implement a standard CAN bus high level protocol but I need to manage standard errors) ?

regards

0 Kudos

1,984 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi cybaaluke,

    I have checked the SDK sample code, it doesn't have the bus off code, so we need to write it by referring the user manual.

   Here, I will give you the step:

1. check the PSR[BO], if it is set, it means the bus off, we can do the bus off recovery process.

2. Clear INIT bit, to start the bus off recovery

3. use while to wait the bus off recovery is finished,

  Check PSR[LEC], if it is 0x5 and PSR[BO] =1, just wait.

Eg, while((PSR[LEC] ==0x5)||(PSR[BO] ==1));

After the while is run over, it means your bus off is recovery.

You can try it on your side.

Besides, you also can use the interrupt to detect the bus off, but you need to enable IE[BOE], and clear IR[BO]in interrupt handler. then do the bus off recovery process.

Please try it on your side, if you still have question about it, please kindly let me know.

Yes, you need to check the errors status when you do the CAN operation.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,984 Views
cybaluke
Contributor III

Thanks Kerry  Zhou for your help.

Starting from your suggestion I can manage the bus-off condition, (I followed your steps but unfortunately in my application I can solve the bus off condition only with a full reset of the MCAN0 peripheral).

Now I have to solve the problem of the CAN bus ErrorPassive condition (in my application the CANdevice can be disconnected from the physical bus and I have to manage this condition, when this  happen I can see an ErrorPassive indication, after this when the CANdevice is re-connected to the bus I have to recover the right working state), what is the right way to manage these conditions in your opinion?

(Can you suggest a step guide to start from for the ErrorPassive recovery? )

thanks