The mask issue for flexcan

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

The mask issue for flexcan

跳至解决方案
1,568 次查看
colinluan
Contributor III

Hi all,

I am developing flexcan in my project, but I met a strange issue as following:

#define FITERMASK FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(rxIdentifier, 0, 0)
#define FIFOMASK FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(0x7FF, 0, 0)

static void flexcan_callback(CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData)
{
	switch (status)
	    {
	        /* Process FlexCAN Rx event. */
			case kStatus_FLEXCAN_TxIdle:
				PRINTF("MB %d - status = %d = kStatus_FLEXCAN_TxIdle\r\n",result,status);
		    	if (TX_MESSAGE_BUFFER_NUM == result)
				{
					txComplete = true;
				}
				break;
	        case kStatus_FLEXCAN_RxIdle:
	            if (RX_MESSAGE_BUFFER_NUM == result)
	            {
	                rxComplete = true;
	            }
	            break;

	        case kStatus_FLEXCAN_RxFifoIdle:
	        	PRINTF("status = %d = kStatus_FLEXCAN_RxFifoIdle\r\n",status);
	        	PrintFrameInfo(&rxFrame);
	        	FLEXCAN_TransferReceiveFifoNonBlocking(EXAMPLE_CAN,&flexcanHandle, &rxfifoXfer);
	        	break;

	        default:
	        	PRINTF("status = %d \r\n",status);
	            break;
	    }
}

int flexCanTest3(void)
{
    flexcan_config_t flexcanConfig;
    flexcan_rx_mb_config_t mbConfig;
    flexcan_rx_fifo_config_t rxFifoConfig;
    uint32_t rxFifoFilter[] = {FITERMASK};

    /*Clock setting for FLEXCAN*/
    CLOCK_SetMux(kCLOCK_CanMux, FLEXCAN_CLOCK_SOURCE_SELECT);
    CLOCK_SetDiv(kCLOCK_CanDiv, FLEXCAN_CLOCK_SOURCE_DIVIDER);

    PRINTF("\r\n==FlexCAN loopback example -- Start.==\r\n\r\n");

    rxIdentifier = 0x001;
    /* Init FlexCAN module. */
    FLEXCAN_GetDefaultConfig(&flexcanConfig);
//    flexcanConfig.enableLoopBack = true;
    flexcanConfig.baudRate = 1000000U;
    FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig, EXAMPLE_CAN_CLK_FREQ);


    rxFifoConfig.idFilterNum = sizeof(rxFifoFilter) / sizeof(rxFifoFilter[0]);
    rxFifoConfig.idFilterTable = rxFifoFilter;
    rxFifoConfig.idFilterType = kFLEXCAN_RxFifoFilterTypeA;
    rxFifoConfig.priority = kFLEXCAN_RxFifoPrioHigh;
    FLEXCAN_SetRxFifoConfig(EXAMPLE_CAN, &rxFifoConfig, true);

    FLEXCAN_SetRxFifoGlobalMask(EXAMPLE_CAN, FIFOMASK);
//    FLEXCAN_SetRxIndividualMask(EXAMPLE_CAN, 0, FIFOMASK);

//    /* Setup Rx Message Buffer. */
    FLEXCAN_SetTxMbConfig(EXAMPLE_CAN, TX_MESSAGE_BUFFER_NUM, true);
    /* Create FlexCAN handle structure and set call back function. */
    FLEXCAN_TransferCreateHandle(EXAMPLE_CAN, &flexcanHandle, flexcan_callback, NULL);

    /* Prepare Tx Frame for sending. */
    rxfifoXfer.frame = &rxFrame;
    FLEXCAN_TransferReceiveFifoNonBlocking(EXAMPLE_CAN, &flexcanHandle, &rxfifoXfer);
    while(1) {
    	vTaskDelay(10);
    }
}

I want to receive messages with ID 0x001, I set filter as:

#define FITERMASK FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(rxIdentifier, 0, 0)

 and if I set mask as:

#define FIFOMASK FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(0x0, 0, 0)

I can receive all ID messages, but if I set mask as:

#define FIFOMASK FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(0x7FF, 0, 0)

I set ID mask bit as 0x7FF to check all ID bits, but I only can receive 1 message which ID is 0x0, I can't receive any message which ID is 0x001;

I'd like to know why I can't receive correct message?

I sent message use a can debug tool, and messages as bellow:

can card.png

0 项奖励
回复
1 解答
1,538 次查看
colinluan
Contributor III

Hi,@Alexis_A

I have resolved the issue. I defined the rxFifoFilter as temporary variable, and the rxFifoConfig.idFilterTable only points to the rxFifoFilter. If this function completes, the rxFifoFilter will be released, so I can not get my expected result. The solution is set rxFifoFilter as a global variable. Thanks for you help.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,545 次查看
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @colinluan,

Looking at your code it looks like the rxFifoConfig structure is not filled. This structure is the list of ID that the FIFO will accept and the mask is used to accept more IDs than the ones in this list. So if you want to accept only the 0x1 ID, try to fill the structure and use the 0x7FF as mask.

Best Regards,

Alexis Andalon

0 项奖励
回复
1,539 次查看
colinluan
Contributor III

Hi,@Alexis_A

I have resolved the issue. I defined the rxFifoFilter as temporary variable, and the rxFifoConfig.idFilterTable only points to the rxFifoFilter. If this function completes, the rxFifoFilter will be released, so I can not get my expected result. The solution is set rxFifoFilter as a global variable. Thanks for you help.

0 项奖励
回复