CAN multiple transmission

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

CAN multiple transmission

2,359 Views
vladstoica
Contributor III


Hello,

 

How can I transmit on CAN mutiple frames with the same MB? I tried to use MB[0] for multiple transmission, with the same id or with different id, but when I try to receive, I only receive the last frame transmitted, not the all of them.

 

Thanks,

 

Vlad

Labels (1)
6 Replies

1,898 Views
martin_kovar
NXP Employee
NXP Employee

Hi Vlad,

how many MB's you use for reception? If you use only one MB for reception, you have to read this MB between the transmissions, otherwise you will lose all messages except the last. Also overrun bit in MB will be set.

I do not know your use case, but I think the easiest way is to configure more MB's for reception.

Regards,

Martin

0 Kudos
Reply

1,898 Views
vladstoica
Contributor III

Thanks Martin for your answer.

I use only one for reception, and one for transmission. In my case, I need to transmit 512 bytes. But how can I receive multiple frames in one MB? Should I clear the MB frame after reception and the other one will be received instant?

Thanks,

Vlad

0 Kudos
Reply

1,898 Views
martin_kovar
NXP Employee
NXP Employee

Hi Vlad,

at first, please read Receive process chapter in FlexCAN module (I do not know, which micro you use).

In general, you should do following steps:

1) Write the ID word and write EMPTY code.

2) After you receive the frame, you get interrupt flag.

3) Read the Control and Status word of that MB - this operation lock the MB

4) Now you can read data from MB

5) Acknowledge the proper flag at IFLAG registers.

6) Read the Free Running Timer. It is optional but recommended to unlock Mailbox as

soon as possible and make it available for reception.

But you have to do points 3-6 between message transmission. If you send messages too fast, you do not have to be able to receive all messages.

You can look at the following example, how to implement FlexCAN TX/RX using interrupt:

Example MPC5775K FlexCAN_with_interrupts S32DS

Regards,

Martin

0 Kudos
Reply

1,898 Views
vladstoica
Contributor III

My use case is: I have two EVB with MPC5748G, and on one EVB I will upload a program that will transmit a buffer of 512 bytes using MB[0] let's say. In the other EVB, I will upload a program that will receive in MB[4] all the MB[0]->Data send from first application .

I belive this example with the interupt is for the same EVB, I  don't know if it works in my case. I mean, how to verify if a new frame is received, if the other program sends data without having control over him (being in the second program).?

Vlad

0 Kudos
Reply

1,898 Views
alexvinchev
Contributor V

vladstoica, can I ask one clarifying question (since MPC5748G is CANFD capable):

Do you use FlexCAN in CAN or CANFD mode?

In case of CAN mode you can transmit up to 8 bytes in one frame. In case of CANFD mode it is up to your configuration what is the maximum message size (still limited to 96 bytes at max), but I think MB[4] in CANFD case doesn't even exist, so I would assume you are using CAN, not CANFD.

In my trials I was able to use without problems single TX MB to send CAN frames at 230-250uS on 500kbps CAN bus, which is quite normal for software handling, no DMA in use. You have to prepare TX interrupt handler and when message is sent, load next one, quite simple.

Regarding RX, you have to setup few MB to accept your frames in order to not lose something if you delay your RX message processing.

You can do also without interrupts, but you have to poll the corresponding IFLAG register...

0 Kudos
Reply

1,898 Views
martin_kovar
NXP Employee
NXP Employee

Hi Vlad,

your use case is pretty clear, but this changes nothing about MB handling. One massage buffer is able to save 8 bytes. If you send 512 bytes and you have only one message buffer to receive data, you have to handle every frame you receive. For example, you can create some buffer (array, or something like that) and after each received frame move the data from MB to the buffer you have created. When you send all data, you can check you buffer and you should find there all received data (if your code will work correct).

During the reception, please follow the steps in my previous post and also look at the reference manual chapter 43.5.3 Receive process.

Regards,

Martin