Receiving multiple CAN ids

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

Receiving multiple CAN ids

3,185 Views
Milado
Contributor II

Hello,

I'm trying to receive multiple CAN IDs from a mailbox like the code below, but I'm not getting all the IDs.

After initializing FlexCAN, I configured RxMask like the code below .

I don't want to use "Receive Blocking" because it affects my system and the CAN period.

I don't want to use while to "get transfer status" because it crashes my system.

 

I don't know how to use callback for Rx!

 

 

uint32_t MessageId;
flexcan_msgbuff_t recvBuff_1;
uint16_t ID_1;
uint16_t ID_2;
uint16_t ID_3;

FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_GLOBAL);
FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, 0U);

flexcan_data_info_t dataInfo =
{
.data_length = 8U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
.enable_brs = false,
.fd_enable = false,
.fd_padding = 0U
 };
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1,RX_MAILBOX,&dataInfo ,MessageId);

FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff_1);
if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) ==STATUS_BUSY){};
ID_1 = recvBuff_1.msgId

FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff_2);
if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) ==STATUS_BUSY){};
ID_2 = recvBuff_2.msgId

FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff_3);
if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) ==STATUS_BUSY){};
ID_3 = recvBuff_3.msgId

 

 

Every time I get one/two id(s) by chance. But I want to receive multiple IDs one after another.

 

Do you have any ideas?

 

Thank you in advance.

0 Kudos
Reply
12 Replies

3,170 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

you should call FLEXCAN_DRV_Receive to start receiving a message and after successful receive to start it again. So a code could be

FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1,RX_MAILBOX,&dataInfo ,MessageId);

FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff_1);

while(1)
{
    if(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) == STATUS_SUCCESS)
    {
       ID_1 = recvBuff_1.msgId;
       FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff_1);
    }

}

Usage of callbacks are given for example here https://community.nxp.com/t5/S32K-Knowledge-Base/Example-S32K144-FlexCAN-TX-RX-Error-ISR-test-S32DS2...

 

BR, Petr

0 Kudos
Reply

3,159 Views
Milado
Contributor II

Thank you for your reply.

 

is it possible to avoid while?

 

I'm using un RTOS, if I use while it will block my system.

0 Kudos
Reply

3,151 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, it is.

BR, Petr

Tags (1)
0 Kudos
Reply

3,120 Views
Milado
Contributor II

Hi,

This does not work with FLEXCAN_DRV_Receive as I expected.

Therefore, I switched to FLEXCAN_DRV_RxFifo to receive CAN. It works and I receive several IDs as I expected, but the transmission does not work anymore.

Do you have any idea why the transmission does not work anymore when I use RxFifo? 

I use mailbox0 for RxFifo and mailbox 1 for transmission. I configured CAN driver like below :

Should I consider another configuration?

 

Milado_0-1648650297341.png

 

 

Thak you in advance,

Milad

0 Kudos
Reply

3,097 Views
Milado
Contributor II

Hi ,

 

I changed the mailbox from 1 to 10 for the transmission and it works, now,

 

I don't know why it doesn't work with mailbox 1 & 2 ...

 

Milad

0 Kudos
Reply

3,091 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if RXFIFO is used then first few MBs are occupied by RXFIFO (MB0-MB5) and ID filter table. CLR2[RFFN] description shows this

PetrS_0-1648754733263.png

So for default RFFN=0, there is 8 filter elements on area of MB6/MB7, so remaining MB that can be used for TX/RX starts at MB8.

BR, Petr 

 

3,027 Views
Milado
Contributor II

Hi, 

Thank you for your answer.

I saw in the S32 document that RXFifo has a depth of 6 messages. 

Is it possible to increase this number? 

 I want to receive 28 messages in one sending, but once I capture them, I only get 6 messages. To capture the others, I have to send them back.

 

Thank you in advance,

 

BR,

Milad

0 Kudos
Reply

3,014 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

no RXFIFO depth is fixed, cannot be extended.

BR, Petr 

0 Kudos
Reply

2,992 Views
Milado
Contributor II

Hi,

According to the RM, RxFifo will be cleared after each reception. If I send more than 6 messages, the others will be cleared. 

Milado_0-1649768143751.png

 

If it is not possible to extend the depth of RXFIFO, then is it possible not to clear the RXFifo buffer after receiving 6 messages? I mean keep the messages or put them on hold to retrieve them in another call.

 

Thank you,

BR,

Milad

0 Kudos
Reply

2,972 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if you receive 6 messages into RXFIFO it remains in RXFIFO until you read it and clear BUFI5 after each read out. Further message received which belongs to RXFIFO will be lost because there is no space in it.

BR, Petr

0 Kudos
Reply

2,845 Views
Milado
Contributor II

Hi,

In this case, is it possible to use eDMA? to store the messages received from RXFIFO directly in memory. Therefore RXFIFO will be readed every time, so never fill and I have other messages.

The role of RXFIFO will be to receive and pass messages to eDMA but not to store them in the RXFIFO buffer.

 

Thank you in advance.

Milad

0 Kudos
Reply

2,833 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, DMA can be used to read RXFIFO, see more in chapter 55.3.9.1 Rx FIFO under DMA operation of the RM.

BR, Petr

0 Kudos
Reply