LPC43xx CAN interrupt direction (LPCOpen)

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

LPC43xx CAN interrupt direction (LPCOpen)

863 Views
quex
Contributor I

Hello,

what is the right way to identify whether the active CAN interrupt on LPC43xx is caused by message transmission or reception if I do not want to or can't keep track of which message object is used for tx/rx?

In the interrupt routine I call Chip_CCAN_GetIntID (LPC_CCAN_T *pCCAN) that gives me the number of message object which is the source of the interrupt.

Then I can read the status register using Chip_CCAN_GetStatus (LPC_CCAN_T *pCCAN) and use the TXOK and RXOK bits to detect if the interrupt was triggered by transmission or direction; however, both of these bits could be 1 at the same time which would prevent the direction identification.

The other way I can think of would be using the Chip_CCAN_GetMsgObject function and then reading the DIR bit of the IFx_ARB2 register.

Is there any more elegant way? E.g. would it be possible to use the ND1/2 registers?

Thanks in advance for any ideas / clarification

Labels (2)
0 Kudos
Reply
2 Replies

593 Views
quex
Contributor I

Hello Kerry,

thank you for your reply.

The approach in the example is fine for an example project where you know what identifiers are assigned to which direction. The code I'm working on is a driver which won't have the information. (It could be done by storing the data while the higher level application configures the MOBs, but it's quite complex and therefore rather impractical).

Using RXOK & TXOK status bits would be the simplest way. However, I'm afraid there is a (remote) possibility that both could be set when I check them even if I clear them at every interrupt. E.g. if my application sends a message, NVIC fires an interrupt, but before I manage to check the status and clear the TXOK flag a new message gets received and sets the RXOK flag. Then I'd end up with both RXOK and TXOK set.

Long story short: I decided to use the DIR bit of the IFx_ARB2 register, which seems to be the safe way to go.

0 Kudos
Reply

593 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi quex,

    You can refer to the LPCopen sample code, check the ID, because the transfer ID and receive ID is defined by the code, you can know it.

    Just like the LPCopen CAN0_IRQHandler code.

pastedImage_1.png

  About the CCAN_STAT_TXOK and CCAN_STAT_RXOK question, you also can check it, but when you find it is set, you can clear it, then the next time, you will know the direction.

Before send and receive the CAN data, please do :

Chip_CCAN_ClearStatus(pCCAN, (CCAN_STAT_RXOK | CCAN_STAT_TXOK));

Then you can read the status in the interrupt routine, when the according bit is set, you can get the direction, then clear it immediately.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

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

0 Kudos
Reply