****************************************************************************************************
#define RX_MESSAGE_BUFFER_NUM (10)
#define TX_MESSAGE_BUFFER_NUM (9)
#define DLC (8)
#define BUF_SIZE (13)
****************************************************************************************************
flexcan_frame_t rxFrame;
volatile bool rxComplete = false;
uint8_t RX_BUF[BUF_SIZE];
****************************************************************************************************
/*
* This part is the implementation of interrupt service routine, this is invoked when new data arrives
* When the ISR is called it first checks the status of a flag indicating new data has arrived on RX_MESSAGE_BUFFER_NUM
* If the flag is set, it clears the flag and then reads the data from message buffer into rxFrame
* the rxComplete variable is set to indicate that the new message has been received
* SDK_ISR_EXIT_BARRIER is called for exiting the ISR
*/
****************************************************************************************************
void CAN1_FLEXCAN_IRQHANDLER(void)
{
uint64_t flag = 1U;
/* If new data arrived. */
if (0U != FLEXCAN_GetMbStatusFlags(CAN1_PERIPHERAL, flag << RX_MESSAGE_BUFFER_NUM))
{
FLEXCAN_ClearMbStatusFlags(CAN1_PERIPHERAL, flag << RX_MESSAGE_BUFFER_NUM);
(void)FLEXCAN_ReadRxMb(CAN1_PERIPHERAL, RX_MESSAGE_BUFFER_NUM, &rxFrame);
rxComplete = true;
}
SDK_ISR_EXIT_BARRIER;
}
****************************************************************************************************
int main(void)
{
uint64_t flag = 1U;
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
/* Init FSL debug console. */
BOARD_InitDebugConsole();
#endif
***********************************************configuration API****************************************************
NVIC_SetPriority(CAN1_FLEXCAN_IRQN, CAN1_FLEXCAN_IRQ_PRIORITY);
EnableIRQ(CAN1_FLEXCAN_IRQN);
FLEXCAN_Init(CAN1_PERIPHERAL, &CAN1_config, CAN1_CLOCK_SOURCE);
/* Message buffer 0 initialization */
FLEXCAN_SetRxMbConfig(CAN1_PERIPHERAL, 10, &CAN1_rx_mb_config_0, true);
/* Enable Rx Message Buffer interrupt. */
FLEXCAN_EnableMbInterrupts(CAN1_PERIPHERAL, flag << RX_MESSAGE_BUFFER_NUM);
while(1)
{
if(rxComplete == true)
{
RX_BUF[0] = ((rxFrame.id>>2) >> 24 & (0xFFU));
RX_BUF[1] = ((rxFrame.id>>2) >> 16 & (0xFFU));
RX_BUF[2] = (rxFrame.length & (0xFFU)) ;
RX_BUF[3] = (rxFrame.dataWord0 >> 24 & (0xFFU));
RX_BUF[4] = (rxFrame.dataWord0 >> 16 & (0xFFU));
RX_BUF[5] = (rxFrame.dataWord0 >> 8 & (0xFFU));
RX_BUF[6] = ((rxFrame.dataWord0 >> 0) & (0xFFU));
RX_BUF[7] = (rxFrame.dataWord1 >> 24 & (0xFFU));
RX_BUF[8] = ((rxFrame.dataWord1 >> 16) & (0xFFU));
RX_BUF[9] = ((rxFrame.dataWord1 >> & (0xFFU));
RX_BUF[10] = ((rxFrame.dataWord1 >> 0 ) & (0xFFU));
LPUART_WriteBlocking(LPUART1_PERIPHERAL,RX_BUF, sizeof(RX_BUF));
rxComplete = false;
}
}
}
above code work for single frame in our code we need to configure multiple ID for that we configure multiple Message buffer
/* Message buffer 0 initialization - 10 number of MB*/
FLEXCAN_SetRxMbConfig(CAN1_PERIPHERAL, 10, &CAN1_rx_mb_config_0, true);
/* Message buffer 1 initialization-11 number of MB */
FLEXCAN_SetRxMbConfig(CAN1_PERIPHERAL, 11, &CAN1_rx_mb_config_1, true);
/* Message buffer 2 initialization-12 number of MB */
FLEXCAN_SetRxMbConfig(CAN1_PERIPHERAL, 12, &CAN1_rx_mb_config_2, true);
also enable rx msg buffer interrupt IMASK register
/* Enable Rx Message Buffer interrupt for 10 number of MB. */
FLEXCAN_EnableMbInterrupts(CAN1_PERIPHERAL, flag << 10);
/* Enable Rx Message Buffer interrupt.for 11 number of MB. */
FLEXCAN_EnableMbInterrupts(CAN1_PERIPHERAL, flag << 11);
/* Enable Rx Message Buffer interrupt.for 12 number of MB. */
FLEXCAN_EnableMbInterrupts(CAN1_PERIPHERAL, flag << 12);
here we use different MB for different ID but not able to receive multiple frame ,please assist how multiple ID frame receive ? Is there any SDK example code of Flexcan1 for multiple ID