The mask issue for flexcan

cancel
Showing results for 
Search instead for 
Did you mean: 

The mask issue for flexcan

Jump to solution
137 Views
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 Kudos
1 Solution
107 Views
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.

View solution in original post

0 Kudos
2 Replies
114 Views
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 Kudos
108 Views
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.

View solution in original post

0 Kudos