FlexCAN multiple ID Rx

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

FlexCAN multiple ID Rx

Jump to solution
2,451 Views
robertyork
Contributor II

I'm using MQX 4.1 and the FlexCAN drivers, and I'm running into a problem where my device needs to receive CAN messages with different ID numbers, and so far, I'm getting very sporadic behavior.

The FlexCAN demo has a mailbox mode and FIFO mode, and I was using the mailbox mode fine, with the CAN ID I was looking for. However, when I wanted to have it receive messages with a second ID, I ran into issues. I could change the ID fine by changing the RX_identifier  in the example code, but I've not been able to find a method to get it to accept more than one. I've tried duplicating the code and changing the variables for a second mailbox, but now I seem to randomly be receiving one of the two different IDs. I'll send one of the IDs, and it will receive them fine for 2-4 messages, then it will no longer receive them. If I send the other ID, it will receive that for another few, then stop until I swap IDs again.

I tried changing it to FIFO mode, and now it's not receiving any messages.

Given the general lack of documentation, I'm really at a loss on what to try next, or how to fix this. Any help or examples of working code that receive more than one ID on a message would be appreciated.

Tags (3)
0 Kudos
1 Solution
1,153 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi York:

I tried to receive with multiple CAN ID, it can work.

This issue is related to the register CANx_RXMGMASK., it is used to mask the filter fields of all Rx MBs, excluding MBs 14-15, which have individual mask registers.

For example, we set the register to 0x123,  0x123 = 0001 0010 0011

  result = flexcan_set_rx_mb_global_mask(instance, kFlexCanMbId_Std, 0x123);

In this case, we can receive lots of CAN id,  including 0x123, 0x133, 0x173.......

If you choose the right mask value, you can get the expected result

Regards

Daniel

View solution in original post

0 Kudos
5 Replies
1,153 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Robert

Could you tell me you board, I need it to reproduce your issue in my side.

Regards

Daniel

0 Kudos
1,153 Views
robertyork
Contributor II

Looking over some other questions about the FlexCAN driver, it seems that in the end, I probably don't want the mailbox method, but I'd rather have the RxFIFO version working. The demo contains Rx FIFO code, but I could not get it working at all, even though the MB mode was working fine. So examples on specifically how to change the demo to go into FIFO mode would be great. And of course, then how to set the FIFO up to accept any message ID. I tried playing with the hardware filter flags, and couldn't get the desired result.

0 Kudos
1,153 Views
robertyork
Contributor II

I'm using a custom board that's been practically duplicated off the K70 tower board. Not exactly the same, but very close. I've had some issues with some CAN driver flaws in the past, but now that those are resolved, everything seems to be working great, save I'm having this problem with receiving multiple IDs. By working great, I mean that I can send messages fine, receive them fine (as long as they all have my board's target ID). My first hunch is that I'm simply not doing it right. Either I'm not initializing the multiple MBs correctly, or I'm not polling them right, or something, but I've done quite a bit to duplicate everything in the demo for the two separate MBs. Perhaps that's not the right answer. Any examples of working code with multiple MBs? Even an example on a working Rx FIFO (again, with multiple IDs it can receive) would be great. I can paste my code for the CAN here, in the hacked apart state it's in.

In the meantime I'm trying to get the processor expert CAN drivers working, to see if that's simpler.

0 Kudos
1,154 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi York:

I tried to receive with multiple CAN ID, it can work.

This issue is related to the register CANx_RXMGMASK., it is used to mask the filter fields of all Rx MBs, excluding MBs 14-15, which have individual mask registers.

For example, we set the register to 0x123,  0x123 = 0001 0010 0011

  result = flexcan_set_rx_mb_global_mask(instance, kFlexCanMbId_Std, 0x123);

In this case, we can receive lots of CAN id,  including 0x123, 0x133, 0x173.......

If you choose the right mask value, you can get the expected result

Regards

Daniel

0 Kudos
1,153 Views
robertyork
Contributor II

Okay, after much testing and prodding, I've gotten the mask to work properly now. Namely, I can set a mask to accept any messages. That may lead to other issues, but that's a different problem.

Thanks for the help with this. Not sure why I didn't figure it out earlier.

Now the big question is how to get FIFO mode working so I don't miss messages.

0 Kudos