CAN FLEXCAN_EVENT_RX_COMPLETE interrupt issue

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

CAN FLEXCAN_EVENT_RX_COMPLETE interrupt issue

5,674 Views
rinkuyadav
Contributor I

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;
}
}

Labels (1)
Tags (1)
4 Replies

3,468 Views
rohit_alate
Contributor II

Hello Team,
i installed the callback but i am not coming inside this,

Can anyone help me out here,
it will really helpful because i am very new in these things,
My code :

void InitCAN(void)
{

CAN_Init(&can_pal1_instance, &can_pal1_Config0);

/* Set information about the data
* - 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 RxbuffCfg = {
.enableFD = false,
.enableBRS = false,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};

/* Configure RX buffer with index RX_MAILBOX */
CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &RxbuffCfg, RX_MSG_ID);
CAN_InstallEventCallback(&can_pal1_instance, flexcan0_Callback, NULL);

}
void CAN_main(void )
{
while(1)
{
CAN_Send_DATA();
/* Start receiving data in RX_MAILBOX. */
CAN_Receive(&can_pal1_instance, RX_MAILBOX, &recvMsg);
/* Wait until the previous FlexCAN receive is completed */
while(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY);

UpdateRecivedDataIntoBuffer();

}




Thanks in Advance,
Rohit

0 Kudos
Reply

4,206 Views
dennis_hage
Contributor I

Hi,

I was struggling with the same problem, but solved it for me - without the Rx FIFO.

Examinating the FLEXCAN driver files and the CAN PAL files I found that it is sufficient to invoke the non-blocking receive function.

In the mentioned example above it would be

CAN_Receive(INST_CAN_PAL1, RX_MAILBOX, &recvMsg);

where recvMsg should be declared as a global variable if you want to use it in the callback function.

CAN_Receive will call FLEXCAN_StartRxMessageBufferData where the corresponding interrupt mask flag in IMASK1 of the CAN instance is set by FLEXCAN_SetMsgBuffIntCmd.

When a message is received in mailbox RX_MAILBOX, the installed callback function will be invoked.

Before the callback function is called, the mailbox interrupt flag is cleared by FLEXCAN_CompleteTransfer. To receive further messages you have to call CAN_Receive again. It works for me to do this in the callback function directly.

I hope this helps!

Best wishes,

Dennis

4,205 Views
alexandrunan
NXP Employee
NXP Employee

Hello, to receive any message ID and type you need to set CAN on RX FIFO mode, and to set the acceptance filter corresponding to 0. 

config structures:

/*! @brief PAL instance information */
const can_instance_t can_pal1_instance = {CAN_INST_TYPE_FLEXCAN, 0U};

/*! @brief Rx FIFO extension */
extension_flexcan_rx_fifo_t can_pal1_rx_fifo_ext0 = {
.numIdFilters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.idFormat = FLEXCAN_RX_FIFO_ID_FORMAT_A,
/* User must pass reference to the ID filter table. */
.idFilterTable = NULL
};

/*! @brief User configuration structure */
const can_user_config_t can_pal1_Config0 = {
.maxBuffNum = 16UL,
.mode = CAN_NORMAL_MODE,
.peClkSrc = CAN_CLK_SOURCE_OSC,
.enableFD = false,
.payloadSize = CAN_PAYLOAD_SIZE_8,
.nominalBitrate = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.dataBitrate = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.extension = &can_pal1_rx_fifo_ext0
};

int main(void)
{
status_t status;
flexcan_id_table_t flTable[10];
/*** 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. ***/
uint8_t i;
for(i=0;i<10;i++)
{
flTable[i].id=i;
flTable[i].isExtendedFrame=true;
flTable[i].isRemoteFrame=false;
}
/* Do the initializations required for this application */
BoardInit();
GPIOInit();
can_pal1_rx_fifo_ext0.idFilterTable = &flTable;

status = CAN_Init(&can_pal1_instance, &can_pal1_Config0);
DEV_ASSERT(status == STATUS_SUCCESS);
CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_EXT,1, 0);
while(1)
{
/* Define receive buffer */
can_message_t recvMsg;

/* Start receiving data in RX_MAILBOX. */
CAN_Receive(&can_pal1_instance, 0U, &recvMsg);

/* Wait until the previous FlexCAN receive is completed */
while(CAN_GetTransferStatus(&can_pal1_instance, 0U) == STATUS_BUSY);

}

}

0 Kudos
Reply

3,830 Views
blavk
Contributor I

hello,

I have a S32K148EVB board.I need a full routine program to use CAN0 and UJA1132, configuring board by myself  don't work.

thank you

Tags (3)
0 Kudos
Reply