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.
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
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?
Thak you in advance,
Milad
Hi,
if RXFIFO is used then first few MBs are occupied by RXFIFO (MB0-MB5) and ID filter table. CLR2[RFFN] description shows this
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
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
Hi,
According to the RM, RxFifo will be cleared after each reception. If I send more than 6 messages, the others will be cleared.
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
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
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