s32k118 CAN Rx Interrupt

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

s32k118 CAN Rx Interrupt

Jump to solution
2,148 Views
ArushThomas
Contributor III

Hi all,

I am using the s32k118 MCU and need to interface with a CAN bus. I've been polling the CAN bus every 100ms with the CAN_Receive() function to retrieve any messages from the bus, but unfortunately I do miss a lot of messages, since there are more than one message on the bus every 100ms.

My end goal is to asynchronously add all received messages to a Queue of CAN messages, which I can parse periodically. I was hoping to accomplish this with a CAN Rx Interrupt, which would be triggered whenever the MCU detects a message on the bus. Unfortunately, I'm not able to set up such an ISR.

 

I've tried setting up an ISR with the interrupt_manager component, on the CAN0_ORed_0_31_MB_IRQn IRQ. But it seems my ISR is being triggered only after I call CAN_Receive() in my main() function. This does not meet my requirements, as I was hoping to all the CAN_Receive() function exclusively in the ISR. Furthermore, after being triggered once, the code appears to get stuck in continuously calling the ISR over and over.

I tried installing a callback function with CAN_InstallEventCallback(), but again, the callback function is only called after I call CAN_Receive() or CAN_Send(). So again, it doesn't seem like I can depend on the Callback to catch all messages from the bus.

Finally, I used the Rx FIFO feature, which does successfully add all messages to a the Mailbox 0 in a buffer-type format. This is what I need... except it's limited to a maximum of 6 messages. 

ArushThomas_0-1718187128272.png

I'm anticipating a need for ~16 messages to be buffered at a time.

 

To illustrate the issues I've faced with Polling, ISR and Callback, I've attached a "CAN_Example" project. Hope it serves to further clarify the problem.

 

How do I accomplish this task, of buffering incoming CAN messages for future parsing?

Tags (2)
0 Kudos
Reply
1 Solution
2,123 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@ArushThomas

You can refer to the demo in the link below which shows how to receive or transmit CAN frames using MB or FIFO interrupts.

https://community.nxp.com/t5/S32K-Knowledge-Base/S32K1xx-FlexCAN-Mask-Setting-Demo/ta-p/1519753

 

View solution in original post

0 Kudos
Reply
2 Replies
2,124 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@ArushThomas

You can refer to the demo in the link below which shows how to receive or transmit CAN frames using MB or FIFO interrupts.

https://community.nxp.com/t5/S32K-Knowledge-Base/S32K1xx-FlexCAN-Mask-Setting-Demo/ta-p/1519753

 

0 Kudos
Reply
2,105 Views
ArushThomas
Contributor III

Thanks, that solves the issue!

Seems like the key point I'd missed was to call FLEXCAN_DRV_Receive(),  FLEXCAN_DRV_RxFifo() or CAN_Receive() at least once on each Mailbox, for the Callback to work properly.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1886051%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Es32k118%20CAN%20Rx%20Interrupt%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1886051%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3EI%20am%20using%20the%20s32k118%20MCU%20and%20need%20to%20interface%20with%20a%20CAN%20bus.%20I've%20been%20polling%20the%20CAN%20bus%20every%20100ms%20with%20the%26nbsp%3BCAN_Receive()%20function%20to%20retrieve%20any%20messages%20from%20the%20bus%2C%20but%20unfortunately%20I%20do%20miss%20a%20lot%20of%20messages%2C%20since%20there%20are%20more%20than%20one%20message%20on%20the%20bus%20every%20100ms.%3C%2FP%3E%3CP%3EMy%20end%20goal%20is%20to%20asynchronously%20add%20all%20received%20messages%20to%20a%20Queue%20of%20CAN%20messages%2C%20which%20I%20can%20parse%20periodically.%20I%20was%20hoping%20to%20accomplish%20this%20with%20a%20CAN%20Rx%20Interrupt%2C%20which%20would%20be%20triggered%20whenever%20the%20MCU%20detects%20a%20message%20on%20the%20bus.%20Unfortunately%2C%20I'm%20not%20able%20to%20set%20up%20such%20an%20ISR.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EI've%20tried%20setting%20up%20an%20ISR%20with%20the%20interrupt_manager%20component%2C%20on%20the%26nbsp%3BCAN0_ORed_0_31_MB_IRQn%20IRQ.%20But%20it%20seems%20my%20ISR%20is%20being%20triggered%20only%20%3CEM%3Eafter%3C%2FEM%3E%20I%20call%26nbsp%3BCAN_Receive()%20in%20my%20main()%20function.%20This%20does%20not%20meet%20my%20requirements%2C%20as%20I%20was%20hoping%20to%20all%20the%26nbsp%3BCAN_Receive()%20function%20exclusively%20in%20the%20ISR.%20Furthermore%2C%20after%20being%20triggered%20once%2C%20the%20code%20appears%20to%20get%20stuck%20in%20continuously%20calling%20the%20ISR%20over%20and%20over.%3C%2FP%3E%3CP%3EI%20tried%20installing%20a%20callback%20function%20with%26nbsp%3BCAN_InstallEventCallback()%2C%20but%20again%2C%20the%20callback%20function%20is%20only%20called%26nbsp%3B%3CEM%3Eafter%3C%2FEM%3E%20I%20call%26nbsp%3BCAN_Receive()%20or%20CAN_Send().%20So%20again%2C%20it%20doesn't%20seem%20like%20I%20can%20depend%20on%20the%20Callback%20to%20catch%20all%20messages%20from%20the%20bus.%3C%2FP%3E%3CP%3EFinally%2C%20I%20used%20the%20Rx%20FIFO%20feature%2C%20which%20does%20successfully%20add%20all%20messages%20to%20a%20the%20Mailbox%200%20in%20a%20buffer-type%20format.%20This%20is%20what%20I%20need...%20except%20it's%20limited%20to%20a%20maximum%20of%206%20messages.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ArushThomas_0-1718187128272.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22ArushThomas_0-1718187128272.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F283690i91B8E4DC2CACF1C2%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22ArushThomas_0-1718187128272.png%22%20alt%3D%22ArushThomas_0-1718187128272.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI'm%20anticipating%20a%20need%20for%20~16%20messages%20to%20be%20buffered%20at%20a%20time.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ETo%20illustrate%20the%20issues%20I've%20faced%20with%20Polling%2C%20ISR%20and%20Callback%2C%20I've%20attached%20a%20%22CAN_Example%22%20project.%20Hope%20it%20serves%20to%20further%20clarify%20the%20problem.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EHow%20do%20I%20accomplish%20this%20task%2C%20of%20buffering%20incoming%20CAN%20messages%20for%20future%20parsing%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1886627%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20s32k118%20CAN%20Rx%20Interrupt%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1886627%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThanks%2C%20that%20solves%20the%20issue!%3C%2FP%3E%3CP%3ESeems%20like%20the%20key%20point%20I'd%20missed%20was%20to%20call%26nbsp%3B%3CSPAN%3EFLEXCAN_DRV_Receive()%2C%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EFLEXCAN_DRV_RxFifo()%20or%26nbsp%3BCAN_Receive()%20at%20least%20once%20on%20each%20Mailbox%2C%20for%20the%20Callback%20to%20work%20properly.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1886509%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20s32k118%20CAN%20Rx%20Interrupt%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1886509%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CA%20href%3D%22mailto%3AHi%40ArushThomas%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EHi%40ArushThomas%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20refer%20to%20the%20demo%20in%20the%20link%20below%20which%20shows%20how%20to%20receive%20or%20transmit%20CAN%20frames%20using%20MB%20or%20FIFO%20interrupts.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FS32K1xx-FlexCAN-Mask-Setting-Demo%2Fta-p%2F1519753%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FS32K1xx-FlexCAN-Mask-Setting-Demo%2Fta-p%2F1519753%3C%2FA%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E