How to Receive multiple CAN messages

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

How to Receive multiple CAN messages

1,307 Views
Dileep1441
Contributor I

Hi,

I want to receive multiple CAN messages.

Please check the below function which i wrote for receive the single message, but i want to receive multiple messages id's, please do the needful on this requirement.

Thanks in Advance.

 

UINT16 CAN_Rx(UINT32 Rx_Id, UINT8* Data)
{

/* Set information about the data to be sent
* - Standard message ID
* - Bit rate switch enabled to use a different bitrate for the data segment
* - Flexible data rate enabled
* - Use zeros for FD padding
*/
can_buff_config_t buffCfg = {
.enableFD = true,
.enableBRS = true,
.fdPadding = 0U,
.idType = CAN_ID_TYPE,
.isRemote = false
};

/* Define receive buffer */
can_message_t recvMsg;

/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigRxBuff(INST_CAN_PAL1, RX_MAILBOX, &buffCfg, Rx_Id);

/* Start receiving data in RX_MAILBOX. */
CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

/* Wait until the previous FlexCAN receive is completed */
if(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) != STATUS_BUSY)
{
/* Check the received message ID and payload */
if(recvMsg.id == RX_MSG_ID)
{
CAN_Rx_test_ID = recvMsg.id;
}
}

}

0 Kudos
5 Replies

1,292 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @Dileep1441 

Can you tell us the MCU that you are using? And also, which software?

0 Kudos

1,290 Views
Dileep1441
Contributor I

Hi @VaneB ,

Thanks for your reply.

I'm using S32K144 EVB, and Software S32DS ARM 2018.R1

Example code:can_pal_s32k144

 

Please request to share the process and configuration for below requirements:

1.CAN Rx Interrupt Method(when ever the msg received control need to goes to CAN Rx IRQ)

2.CAN Rx Filtering Method(Ex MSG ID's:: 0x10 to 0x20)

3.Multiple CAN Messages Receiving method(need to receive all the messages on the bus)

 

Thanks in Advance.

0 Kudos

1,282 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @Dileep1441 

Firstly I recommend you update the IDE to S32DS 3.4 and the lasted SDK version (S32SDK_S32K1XX_RTM_4.0.3.).

In section 16.33 Controller Area Network - Peripheral Abstraction Layer (CAN PAL) of the S32SDK User Manual, you can find a detailed description and example codes of CAN PAL. You can find it at ...\nxp\S32DS.3.4\S32DS\software\S32SDK_S32K1XX_RTM_4.0.3\doc
NOTE: the previous path is an example of where you can find the S32SDK_S32K144_UserManual

Also, refer to the following community posts that could be useful for you.

0 Kudos

1,263 Views
Dileep1441
Contributor I

Hi @VaneB ,

Thanks for the Reply.

Please check the below code, using below code i can able to receive all the message ID's

but the issue is, that while loop is blocking my remining functionality of the code.

Can you please suggest without while loop or please share the interrupt method code for Rx. 

 

/***********************************************************************************************************************
* Function Name: UINT16 CAN_Rx(UINT32 Rx_Id, UINT8* Data, UINT8 Data_len)
* Description : This function is used to Receive the data on CAN
* Arguments : CAN_MSG_ID, Data, Data length
* Return Value : Status
***********************************************************************************************************************/
UINT16 CAN_Rx(UINT32 Rx_Id, UINT8* Data)
{

/* Set information about the data to be sent
* - Standard message ID
* - Bit rate switch enabled to use a different bitrate for the data segment
* - Flexible data rate enabled
* - Use zeros for FD padding
*/
can_buff_config_t buffCfg = {
.enableFD = true,
.enableBRS = true,
.fdPadding = 0U,
.idType = CAN_ID_TYPE,
.isRemote = false
};

/* Define receive buffer */
can_message_t recvMsg;

/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigRxBuff(INST_CAN_PAL1, RX_MAILBOX, &buffCfg, Rx_Id);
FLEXCAN_DRV_SetRxMbGlobalMask(INST_CAN_PAL1, FLEXCAN_MSG_ID_STD, 0); // All id received masking


/* Start receiving data in RX_MAILBOX. */
CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

while(1)
{
/* Wait until the previous FlexCAN receive is completed */
if(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) == STATUS_SUCCESS) //STATUS_BUSY
{
CAN_Rx_test_ID = recvMsg.id;
CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

/* Check the received message ID and payload */
/* if(recvMsg.id == RX_MSG_ID)
{
CAN_Rx_test_ID = recvMsg.id;
}*/
}
}

}

0 Kudos

1,186 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @Dileep1441 

Please refer ftm_periodic_interrupt example, with this you can see how to work with interruptions.

0 Kudos