Mailboxes and Buffers from flexcan example

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

Mailboxes and Buffers from flexcan example

Jump to solution
5,373 Views
MQXuser
Contributor III

I am trying to use FlexCAN on M52259EVB with the example provided on MQX located at ...\mqx\examples\can\flexcan.

After performing different tests, I figured I need to know the following:

How does the flexcan Buffers work? Are they like a space to store outgoing or incoming messages with an specific ID?
OR
Are they just like: buffer 0 is full so next message goes to buffer 1, if buffer 1 is full then it goes to buffer number 2


Is flexcan receiving its own sent messages, even if LoopBack is disabled?


In the example I already mention, What is call a mailbox ? Is it like a bigger buffer to store multiple messages received/sent with the same identifier OR, is it only the way they call the buffers already implemented into flexcan from the MCU.

In my application 1 master board will be sending and receiving messages to/from 4 slave boards. Therefore, I am trying to define 2 mailboxes (TX and RX) to control each of the slave boards.

In the example provided, there is an installation instruction for different ISR for each mailbox but when I use this function interrupts are not triggered when I send a message with the identifier that corresponds to the mailbox(I am sending messages using canalyzer).

 

I need to clarify the questions above and read check documentation about the code example and flexcan.

 

This is the code I am using to trigger 4 different Interrupts, but it results and triggering only 2 interrupts.

 

 

   GRYPHON_ADDRESS = 1;      RX_Limbic1 = 0;   IdentifierRX_Limbic1 = (GRYPHON_ADDRESS << 3) | 1;//0x09      RX_Limbic2 = 1;   IdentifierRX_Limbic2 = (GRYPHON_ADDRESS << 3) | 2;//0x0A      RX_Limbic3 = 2;   IdentifierRX_Limbic3 = (GRYPHON_ADDRESS << 3) | 3;//0x0B      RX_Limbic4 = 3;   IdentifierRX_Limbic4 = (GRYPHON_ADDRESS << 3) | 4;//0x0C/*All CAN configurations that comes from the example*/result = FLEXCAN_Initialize_mailbox( CAN_DEVICE, RX_Limbic1, IdentifierRX_Limbic1, ack_len_code, FLEXCAN_RX, format, interrupt);   printf("\nFLEXCAN rx mailbox initialization. result: 0x%lx", result);   result = FLEXCAN_Activate_mailbox(CAN_DEVICE, RX_Limbic1, FLEXCAN_RX_MSG_BUFFER_EMPTY);   printf("\nFLEXCAN mailbox activation. result: 0x%lx", result);         /* Initialize mailbox */   result = FLEXCAN_Initialize_mailbox( CAN_DEVICE, RX_Limbic2, IdentifierRX_Limbic2, ack_len_code, FLEXCAN_RX, format, interrupt);   printf("\nFLEXCAN rx mailbox initialization. result: 0x%lx", result);   result = FLEXCAN_Activate_mailbox(CAN_DEVICE, RX_Limbic2, FLEXCAN_RX_MSG_BUFFER_EMPTY);   printf("\nFLEXCAN mailbox activation. result: 0x%lx", result);         /* Initialize mailbox */   result = FLEXCAN_Initialize_mailbox( CAN_DEVICE, RX_Limbic3, IdentifierRX_Limbic3, ack_len_code, FLEXCAN_RX, format, interrupt);   printf("\nFLEXCAN rx mailbox initialization. result: 0x%lx", result);   result = FLEXCAN_Activate_mailbox(CAN_DEVICE, RX_Limbic3, FLEXCAN_RX_MSG_BUFFER_EMPTY);   printf("\nFLEXCAN mailbox activation. result: 0x%lx", result);         /* Initialize mailbox */   result = FLEXCAN_Initialize_mailbox( CAN_DEVICE, RX_Limbic4, IdentifierRX_Limbic4, ack_len_code, FLEXCAN_RX, format, interrupt);   printf("\nFLEXCAN rx mailbox initialization. result: 0x%lx", result);   result = FLEXCAN_Activate_mailbox(CAN_DEVICE, RX_Limbic4, FLEXCAN_RX_MSG_BUFFER_EMPTY);   printf("\nFLEXCAN mailbox activation. result: 0x%lx", result);      /* Install ISR */   if(interrupt == FLEXCAN_ENABLE)   {      result = FLEXCAN_Install_isr( CAN_DEVICE, RX_Limbic1, (pointer)MY_FLEXCAN_ISR1 );      printf("\nFLEXCAN RX ISR install. result: 0x%lx", result);      result = FLEXCAN_Install_isr( CAN_DEVICE, RX_Limbic2, (pointer)MY_FLEXCAN_ISR2  );      printf("\nFLEXCAN RX remote ISR install. result: 0x%lx", result);            result = FLEXCAN_Install_isr( CAN_DEVICE, RX_Limbic3, (pointer)MY_FLEXCAN_ISR3  );      printf("\nFLEXCAN RX remote ISR install. result: 0x%lx", result);            result = FLEXCAN_Install_isr( CAN_DEVICE, RX_Limbic4, (pointer)MY_FLEXCAN_ISR4  );      printf("\nFLEXCAN RX remote ISR install. result: 0x%lx", result);         }while{1} //Just wait to catch interrupts with BP

 

I get 4 interruptions but only 2 ISRs instead of 4.

 

 

Hope you can help me with anything.

Message Edited by MQXuser on 2009-08-29 02:06 AM
0 Kudos
1 Solution
1,090 Views
PetrM
Senior Contributor I

Hello,

 

you specify the mailboxes by index, they are directly mapped to FlexCAN message buffers in register memory area, so if you are using mailbox index 1, you are using FlexCAN HW buffer 1. There's no FIFO and there can be stored just 1 message in each mailbox.

 

Your problem can be in mailbox ID settings, which seem to me too close. When two or more mailbox IDs matches the incoming message, the buffer with the lowest index is used. In your case, I think messages 1 and 3 are matched into mailbox 1, message 2 is matched into mailbox 2 and message 4 is matched into mailbox 4, unless you have set global mask ID too, of course. For more details please see M52259EVB reference manual.

 

FlexCAN can receive its own sent messages in loopback mode or when it has configured RX mailbox with lower index than the TX one to same ID and the packet is not acknowledged on the bus, I think.

 

Regards,

PetrM

 

View solution in original post

0 Kudos
2 Replies
1,090 Views
f1marvel
Contributor I

Dear MQXUser

 

I have the same problem with you(Buffering received message and Self Received Problem). And still I can't handle the problem. If you solve this problem can you send me the source code of the your CAN Source. I really need this. 

 

Thank you so much.

Best Regards

0 Kudos
1,091 Views
PetrM
Senior Contributor I

Hello,

 

you specify the mailboxes by index, they are directly mapped to FlexCAN message buffers in register memory area, so if you are using mailbox index 1, you are using FlexCAN HW buffer 1. There's no FIFO and there can be stored just 1 message in each mailbox.

 

Your problem can be in mailbox ID settings, which seem to me too close. When two or more mailbox IDs matches the incoming message, the buffer with the lowest index is used. In your case, I think messages 1 and 3 are matched into mailbox 1, message 2 is matched into mailbox 2 and message 4 is matched into mailbox 4, unless you have set global mask ID too, of course. For more details please see M52259EVB reference manual.

 

FlexCAN can receive its own sent messages in loopback mode or when it has configured RX mailbox with lower index than the TX one to same ID and the packet is not acknowledged on the bus, I think.

 

Regards,

PetrM

 

0 Kudos