S32K344 FlexCAN: How to setup Rx MB mask to receive the CAN FD messages with different IDs?

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

S32K344 FlexCAN: How to setup Rx MB mask to receive the CAN FD messages with different IDs?

Jump to solution
2,698 Views
DanielLiao
Contributor I

Hi, friends,

I refer to below mask setting demo but I only receive the CAN FD message with single ID.
https://community.nxp.com/t5/S32K-Knowledge-Base/S32K1xx-FlexCAN-Mask-Setting-Demo/ta-p/1519753


Based on below code, I only receive the CAN FD message 64 bytes payload with ID 0x300.
Other IDs could not trigger callback, e.g., ID 0x301 to 0x37F.
Could you help to give me some suggestions?

my main.c listed below,

 

 

uint8 callbackRxCount;
uint8 callbackTxCount;
uint8 callbackOtherCount;
Flexcan_Ip_DataInfoType rx_info = {
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 64U,
		.is_polling = FALSE,
		.is_remote = FALSE
	};

void CANTxRxCallback(uint8 instance,
        Flexcan_Ip_EventType eventType,
        uint32 buffIdx,
        const struct FlexCANState *driverState) {
	switch(eventType) {
	case FLEXCAN_EVENT_RX_COMPLETE:
		callbackRxCount++;
        memset(rxData.data, 0, sizeof(rxData.data));
        FlexCAN_Ip_Receive(INST_FLEXCAN_4, RX_MB_IDX, &rxData, TRUE);
		break;
	case FLEXCAN_EVENT_TX_COMPLETE:
		callbackTxCount++;
		break;
	default:
		callbackOtherCount++;
	}
}

int main(void) {
    Clock_Ip_Init(&Clock_Ip_aClockConfig[0]);
    IntCtrl_Ip_EnableIrq(FlexCAN4_1_IRQn);
    IntCtrl_Ip_InstallHandler(FlexCAN4_1_IRQn, CAN4_ORED_0_31_MB_IRQHandler, NULL_PTR);
    Siul2_Dio_Ip_WritePin(PTD15_EN_PORT , PTD15_EN_PIN, 1U);
	Siul2_Dio_Ip_WritePin(PTD13_STB_PORT , PTD13_STB_PIN, 1U);
    FlexCAN_Ip_Init(INST_FLEXCAN_4, &FlexCAN_State0, &FlexCAN_Config1);
    FlexCAN_Ip_SetStartMode(INST_FLEXCAN_4);

    //set global mask
	FlexCAN_Ip_SetRxMaskType(INST_FLEXCAN_4, FLEXCAN_RX_MASK_GLOBAL);
    FlexCAN_Ip_SetRxMbGlobalMask(INST_FLEXCAN_4, 0xFFFFFF80);
	FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_4, RX_MB_IDX, &rx_info, 0x300);
    FlexCAN_Ip_Receive(INST_FLEXCAN_4, RX_MB_IDX, &rxData, TRUE);

    while (1) {
        if (FlexCAN_Ip_GetTransferStatus(INST_FLEXCAN_4, RX_MB_IDX) != FLEXCAN_STATUS_SUCCESS) {
        	FlexCAN_Ip_MainFunctionRead(INST_FLEXCAN_4, RX_MB_IDX);
        }
    }
}

 

 

Many thanks.
Daniel

0 Kudos
Reply
1 Solution
2,673 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

FlexCAN_Ip_SetRxMaskType, FlexCAN_Ip_SetRxMbGlobalMask functions must be called from StopMode or FreezeMode.
So either move them before FlexCAN_Ip_SetStartMode or call e.g. FlexCAN_Ip_EnterFreezeMode before and FlexCAN_Ip_ExitFreezeMode after.

BR, Petr

View solution in original post

0 Kudos
Reply
2 Replies
2,674 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

FlexCAN_Ip_SetRxMaskType, FlexCAN_Ip_SetRxMbGlobalMask functions must be called from StopMode or FreezeMode.
So either move them before FlexCAN_Ip_SetStartMode or call e.g. FlexCAN_Ip_EnterFreezeMode before and FlexCAN_Ip_ExitFreezeMode after.

BR, Petr

0 Kudos
Reply
2,659 Views
DanielLiao
Contributor I

Hi PetrS,

Thanks for your instruction, now I could receive CAN messages as I expected.

Many thanks.
Daniel

0 Kudos
Reply