How to Receive Multiple CAN Frames

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

How to Receive Multiple CAN Frames

3,691 Views
gbrowne
Contributor II

Hello.

I seem to be missing one piece to our FLEXCAN puzzle...

When I transmit a request, my expectation is that there will be multiple response frames (which could all have the same Message ID or different Message IDs).  The tool I am using will respond 3 times to each request.  However, I only seem to be able to read the first frame received.


What is the best technique to get all response frames?  This is where I have started and have tried a number of different tactics from here:

if (STATUS_SUCCESS == FLEXCAN_DRV_Send(INST_HSCAN, 0, &tx_info, msg_id, mb_data)) {
  if (STATUS_SUCCESS == FLEXCAN_DRV_ReceiveBlocking(INST_HSCAN, 1, &data, 100)) {
    // Now how do I get the other 2 frames?  Or should I use a different method altogether?
  }
}

Any suggestions and/or sample code would be greatly appreciated.

Thanks!

-Greg

6 Replies

2,430 Views
robertboys
Contributor IV

Hello

Is it possible the last two frames are lost because the receiving CAN controller is busy with the first one ?

In a situation like you describe (I am assuming there are multiple CAN controllers sending the responses), it is possible for the responses to come back at 100% bus loading.  This is often unexpected.

Here is a CAN Primer:  Application Note 247: CAN Primer for MCB1700 Board 

Thanks

Bob

0 Kudos

2,430 Views
gbrowne
Contributor II

Hi Robert.

Thanks for the input.

The setup I have right now is a simulator that responds to a single request with 3 independent frames - they could be all the same CAN ID or all different CAN IDs.  There is no other traffic on the CAN bus.

I am used to using an external (Microchip MCP2515) CAN controller, which would allow a frame to be received even if the buffer was full and allow it to overflow into the next buffer.  So, in this case with 3 response frames, they would end up in receive buffers 0, 1, and 2 (assuming the masks and filters were set to all acceptance properly, of course).

So, is there a similar way to use the S32K144 to allow for multiple frames to be received (i.e. how do I prevent them from getting "lost")?

Thanks!

-Greg

0 Kudos

2,430 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi Greg,

Seems you are not using the SDK driver properly, at least what I see from the code snippet.

Send or Receive function returns if the MB was properly prepared for TX or RX operation.

Then a FLEXCAN_DRV_GetTransferStatus() can be used to know if the given MB either transmit or received the message already. After the message is received into the MB, to allow the MB to receive another one you must call FLEXCAN_DRV_Receive again. This could bring a SW overhead and in some cases the message can be lost.

You can test the RXFIFO feature which allows receiving up to 6 message without MCU intervention. See SDK and non-SDK examples on following links:

SDK: https://community.nxp.com/message/894644

Non-SDK: https://community.nxp.com/docs/DOC-335250

 

Hope it helps.

 

BR, Petr

2,430 Views
gbrowne
Contributor II

Hi Petr.

Thanks for taking a look at my post and taking the time to reply.

In my case, I am using the blocking version of the receive call, FLEXCAN_DRV_ReceiveBlocking(), which returns STATUS_SUCCESS, so I would not have to also call FLEXCAN_DRV_GetTransferStatus(), correct?

Even if I place another receive, like below, the second receive returns a STATUS_TIMEOUT:

if (STATUS_SUCCESS == FLEXCAN_DRV_Send(INST_HSCAN, 0, &tx_info, msg_id, mb_data)) {
    if (STATUS_SUCCESS == FLEXCAN_DRV_ReceiveBlocking(INST_HSCAN, 1, &data, 100)) {

        // Gets here because the first frame is received...

        if (STATUS_SUCCESS == FLEXCAN_DRV_ReceiveBlocking(INST_HSCAN, 1, &data, 100)) {
            // Does not get in here because the second receive returns STATUS_TIMEOUT...

        }
    }
}

Am I missing something?

I will try testing out the FIFO, but I would prefer to use FLEXCAN_DRV_ReceiveBlocking() - do you have any sample code that uses this method to receive multiple frames?

Thanks again!

-Greg

0 Kudos

2,430 Views
robertboys
Contributor IV

Hello

I am not sure about your use of a CAN simulator and whether this will affect what you are seeing.

A number of years ago I was doing tests at near 100% bus loading and the CAN controller I was using (was part of a test tool) was the NXP SJA1000.  It was capable of receiving all messages at this high loading.

The speed of the software responding to the presence of a new message was the bottleneck in my tests.  Perhaps you can speed this process up ?

Some people use multiple CAN controllers inside the processors with the acceptance filters set to three different CAN IDs.  The IDs of the messages are carefully selected to be in groups allowing easy acceptance filter configuration.  Sometimes you can filter on the first data byte or a part of it and this can be useful.  This way the messages are spread out among the multiple controllers giving the software more time to grab the messages.

I was testing some tools to see at what point messages were lost - sometimes it was as low as 40% bus loading.  This was not very good.

Bob

0 Kudos

2,430 Views
robertboys
Contributor IV

Hello

There is another issue that could cause this problem.  I think it might be worth mentioning.

If two or more identical CAN frames are put on the bus at the same time, they will be overlaid on top of each other without any interference.  They need the same ID, DLC and data bytes.  Remember that CAN controllers will attempt to send their messages as soon as possible after the idle time.


In the case where two or more identical CAN frames are pu on the bus at the sames time::
Each sender will assume their message was received correctly.  The receiver will see only one CAN message since all the messages are superimposed on each other.


Since each message is exactly the same, there will be no arbitration or bus faults.


This is a rather obscure artifact of CAN and I think this will only show up in small proprietary system as it is highly dependent on the system software.  A system using different CAN IDs will not see this.

Thanks

Bob Boys

bob.boys@arm.com

0 Kudos