AnsweredAssumed Answered

CAN FLEXCAN_EVENT_RX_COMPLETE interrupt issue

Question asked by Rinku Yadav on Jul 18, 2018
Latest reply on Aug 1, 2018 by Alexandru Nan

Hello,

I'm working with S32K148EVB and using CAN_PAL example code from SDK.it is working fine but i want to receive CAN massage on interrupt. So i use CAN_InstallEventCallback API to inable RX interrupt. But it generate interrupt after receive or transmite conplete. Please suggest any methode or any example code to get interrupt for any can massage on CAN bus. I have attached my code below:-

 

#ifdef EVB
/*
* @brief Function to initialize and configure the SBC
*/
void SBCInit(void)
{
LPSPI_DRV_MasterInit(LPSPICOM1, &lpspiCom1State, &lpspiCom1_MasterConfig0);
#ifdef EVB_REV_A
LPSPI1->CFGR1 |= LPSPI_CFGR1_PINCFG(3U);
#endif

uja113x_drv_cfg_t sbc_uja113x1_DrvConfig0 = {
.chipType = UJA1132HW5V0,
.lpspiInstance = LPSPICOM1,
.timeout = 200U
};

/* Initialize SBC */
UJA113X_Init(0U, &sbc_uja113x1_InitConfig0, &sbc_uja113x1_DrvConfig0);
}
#endif

 

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. ***/

/* Do the initializations required for this application */
BoardInit();
#ifdef EVB
SBCInit();
#endif
GPIOInit();

CAN_Init(INST_CAN_PAL1, &can_pal1_Config0);

/* 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_MSG_ID_STD,
.isRemote = false
};

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

CAN_InstallEventCallback(INST_CAN_PAL1, flexcan0_Callback, NULL);

while(1)
{
// /* Define receive buffer */
// can_message_t recvMsg;
//
// /* Start receiving data in RX_MAILBOX. */
// CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);
//
// /* Wait until the previous FlexCAN receive is completed */
// while(CAN_GetTransferStatus(INST_CAN_PAL1, RX_MAILBOX) == STATUS_BUSY);
//
// /* Check the received message ID and payload */
// if((recvMsg.data[0] == LED0_CHANGE_REQUESTED) &&
// recvMsg.id == RX_MSG_ID)
// {
// /* Toggle output value LED1 */
// PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));
// }
// else if((recvMsg.data[0] == LED1_CHANGE_REQUESTED) &&
// recvMsg.id == RX_MSG_ID)
// {
// /* Toggle output value LED0 */
// PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));
// }
}

/*** 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!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/

static void flexcan0_Callback(uint8_t instance,
flexcan_event_type_t eventType,
flexcan_state_t *flexcanState)
{
(void)flexcanState;
(void)instance;

switch(eventType)
{
case FLEXCAN_EVENT_RX_COMPLETE:
PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));
break;
case FLEXCAN_EVENT_TX_COMPLETE:
// PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));
break;
default:
break;
}
}

 

Attachments

Outcomes