About how to config s32k344's flexCAN mailboxes so that it can receive messages with all CAN ids

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

About how to config s32k344's flexCAN mailboxes so that it can receive messages with all CAN ids

Jump to solution
1,182 Views
Flavored_kefir
Contributor I

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:

Flavored_kefir_0-1678727628140.png

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?

 

0 Kudos
1 Solution
1,155 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Flavored_kefir

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

 

View solution in original post

0 Kudos
4 Replies
1,169 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Flavored_kefir

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.

Senlent_1-1678758272906.png

S32K3XX RM-REV 5

72.6.2.5 Rx Mailboxes Global Mask Register (RXMGMASK)

Senlent_0-1678758245071.png

 

0 Kudos
1,160 Views
Flavored_kefir
Contributor I

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

 

 

 

 

 

0 Kudos
1,156 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@Flavored_kefir

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

 

0 Kudos
1,149 Views
Flavored_kefir
Contributor I
It works perfectly after putting the funcion at the last.
Thank you very much for your help.
0 Kudos