Excuse me.I am trying to configure the flexcan mailbox of the s32k344 so that it can receive all CAN ids messages. I referred to the configuration method of the S32K1 series microcontroller in thehttps://community.nxp.com/t5/S32K-Knowledge-Base/S32K1xx-FlexCAN-Mask-Setting-Demo/ta-p/1519753 . But this method still seems to be infeasible. I can only receive packets specifying CAN id(0x333), but not all CANs IDS messages.
My initializing code below:
#define CAN4_MSG0_ID 0x333
Flexcan_Ip_StatusType CAN4_Init(void)
{
Flexcan_Ip_StatusType status = FLEXCAN_STATUS_SUCCESS;
/* disable the external CAN transceiver */
TJA1448_PHY1_DISABLE();
/* FlexCAN IP module initialize */
status = FlexCAN_Ip_Init(INST_FLEXCAN_4, &FlexCAN_State4, &FlexCAN_Config4);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
/* start the FlexCAN module */
status = FlexCAN_Ip_SetStartMode(INST_FLEXCAN_4);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
/* configure the FlexCAN RX MB with ID filter */
status = FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_4, CAN4_RX_MB0_IDX, &can4_rx_mb_data_cofig_info, CAN4_MSG0_ID);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
status = FlexCAN_Ip_SetRxMaskType(INST_FLEXCAN_4, FLEXCAN_RX_MASK_GLOBAL);
status = FlexCAN_Ip_SetRxMbGlobalMask(INST_FLEXCAN_4,0xFFFFFFFF);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
#ifdef CAN4_BKG_CONT_RX
/* use user buffer to start receive */
status = FlexCAN_Ip_Receive(INST_FLEXCAN_4, CAN4_RX_MB0_IDX, &gCAN4_rx_user_buffer[gCAN4_rx_user_buffer_idx%2], FALSE);
#endif /* end of CAN4_BKG_CONT_RX */
/* enable the external CAN transceiver */
TJA1448_PHY1_ENABLE();
return status;
}
my flexcan4 configuration as below:
And my code is based on S32K3 T-BOX BSP package S32K3 Automotive Telematics Box (T-Box) BSPs, Drivers and Middleware
Did I miss some other configiuration? Or something goes wrong with the code?
已解决! 转到解答。
the RXMGMASK can only be written in Freeze mode as it is blocked by hardware in other mode.
so put this funcion at the last and try again.
/* start the FlexCAN module */
status = FlexCAN_Ip_SetStartMode(INST_FLEXCAN_4);
I didn't check your code carefully, but I found that your mask setting is wrong,
0b - The corresponding bit in the filter is "don't care."
1b - The corresponding bit in the filter is checked.
S32K3XX RM-REV 5
72.6.2.5 Rx Mailboxes Global Mask Register (RXMGMASK)
Hi@Senlent
Thank you for your reply. I have tried setting the mask as 0u minutes ago. But it still seems not working.
I set a breakpoint in the callback function. But it wasn't even triggered when a CAN msg was send to my board with id 0x334 or 0x335.
My new code below:
Flexcan_Ip_StatusType CAN4_Init(void)
{
Flexcan_Ip_StatusType status = FLEXCAN_STATUS_SUCCESS;
/* disable the external CAN transceiver */
TJA1448_PHY1_DISABLE();
/* FlexCAN IP module initialize */
status = FlexCAN_Ip_Init(INST_FLEXCAN_4, &FlexCAN_State4, &FlexCAN_Config4);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
/* start the FlexCAN module */
status = FlexCAN_Ip_SetStartMode(INST_FLEXCAN_4);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
status = FlexCAN_Ip_SetRxMaskType(INST_FLEXCAN_4, FLEXCAN_RX_MASK_GLOBAL);
/* configure the FlexCAN RX MB with ID filter */
status = FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_4, CAN4_RX_MB0_IDX, &can4_rx_mb_data_cofig_info, CAN4_MSG0_ID);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
// status = FlexCAN_Ip_SetRxMbGlobalMask(INST_FLEXCAN_4,0xFFFFFFFF);
status = FlexCAN_Ip_SetRxMbGlobalMask(INST_FLEXCAN_4, 0U);
/* stop if error */
BSP_DEV(FLEXCAN_STATUS_SUCCESS == status);
#ifdef CAN4_BKG_CONT_RX
/* use user buffer to start receive */
status = FlexCAN_Ip_Receive(INST_FLEXCAN_4, CAN4_RX_MB0_IDX, &gCAN4_rx_user_buffer[gCAN4_rx_user_buffer_idx%2], FALSE);
#endif /* end of CAN4_BKG_CONT_RX */
/* enable the external CAN transceiver */
TJA1448_PHY1_ENABLE();
return status;
}
the RXMGMASK can only be written in Freeze mode as it is blocked by hardware in other mode.
so put this funcion at the last and try again.
/* start the FlexCAN module */
status = FlexCAN_Ip_SetStartMode(INST_FLEXCAN_4);