Not able to receive multiple can message

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

Not able to receive multiple can message

469 Views
RishikeshB
Contributor II

Hello NXP 

I am trying to receive multiple CAN message using do while but not able to receive it PFA of my code and please let me know what is wrong.

#include "Cpu.h"
#include "S32K148_features.h"
#include "S32K148.h"
volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#define TX_MAILBOX (1UL)
#define TX_PHY_ID 0x74Fu
static const uint8_t msg_data[8] = {0x00, 0x01, 0x2, 0x03, 0x04, 0x05, 0x06, 0x07};
#define RX_MAILBOX (0UL)
#define RX_PHY_ID 0x79Eu


void FlexCANInit(void) //CAN Initialize function
{

FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
}

int main(void)
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */
/* Initialize and configure clocks
* - see clock manager component for details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize pins
*See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
FlexCANInit();
/* Set information about the data to be received
* - 1 byte in length
* - 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
*/

flexcan_data_info_t buff_RxTx_Cfg =
{
.msg_id_type = FLEXCAN_MSG_ID_STD,
.data_length = 8,
.fd_enable = true,
.enable_brs = true,

};

FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, TX_MAILBOX, &buff_RxTx_Cfg,TX_PHY_ID);

FLEXCAN_DRV_Send(INST_CANCOM1,TX_MAILBOX,&buff_RxTx_Cfg,(uint32_t)TX_PHY_ID,msg_data);

/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &buff_RxTx_Cfg, RX_PHY_ID);
/* Define receive buffer */
flexcan_msgbuff_t recvBuff;

/* Set the global mask as "don't care" for each message buffer */
FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, 0U);

/* Configure message buffer 0 for reception */

FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, 0U, &buff_RxTx_Cfg, RX_PHY_ID);

/* Start receiving data in message buffer 0 */

FLEXCAN_DRV_Receive(INST_CANCOM1, 0U, &recvBuff);
do
{
/* if the previous FlexCAN receive is completed */

if ((FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, TX_MAILBOX) != STATUS_BUSY))

FLEXCAN_DRV_Send(INST_CANCOM1,TX_MAILBOX,&buff_RxTx_Cfg,(uint32_t)TX_PHY_ID,msg_data);
continue;
}while((FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, TX_MAILBOX) == STATUS_BUSY));
return 0;
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}

0 Kudos
1 Reply

454 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@RishikerhB

       the return value of this function :FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, TX_MAILBOX) may not always ture or false,so your demo code will run out of do-while loop.

you can modified your demo code like this way.

while(1)
{
/* if the previous FlexCAN receive is completed */
if ((FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, TX_MAILBOX) != STATUS_BUSY))
FLEXCAN_DRV_Send(INST_CANCOM1,TX_MAILBOX,&buff_RxTx_Cfg,(uint32_t)TX_PHY_ID,msg_data);
}
or
do
{
/* if the previous FlexCAN receive is completed */
if ((FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, TX_MAILBOX) != STATUS_BUSY))
FLEXCAN_DRV_Send(INST_CANCOM1,TX_MAILBOX,&buff_RxTx_Cfg,(uint32_t)TX_PHY_ID,msg_data);
}while(1);

 

0 Kudos