CAN with Extended ID filtering, how to set multiple filters?

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

CAN with Extended ID filtering, how to set multiple filters?

跳至解决方案
4,823 次查看
gmk1
Contributor III

Can anyone post working code for CAN Extended ID filtering with multiple filters?

I'm using LPC54618J512BD208 MCU and started off with the CAN example code in NXP Device Firmware Pack. 

I'm able to receive (using Rx FIFO) and transmit CAN messages in & out but only with one filter set.

Expecting some help.

// Rgds, Mani

标签 (3)
1 解答
4,503 次查看
Alexis_A
NXP TechSupport
NXP TechSupport

Hi Manikanta,

This parameter is used to enable more than one filter, if you want to set more than one filter, for example, in the next code:

 /* STD filter config. */
    rxFilter.address = STD_FILTER_OFS;
    rxFilter.idFormat = kMCAN_FrameIDExtend;
    rxFilter.listSize = 2U;
    rxFilter.nmFrame = kMCAN_reject0;
    rxFilter.remFrame = false;
    MCAN_SetFilterConfig(EXAMPLE_MCAN, &rxFilter);

    /*First filter configuration*/
    extendedFilter.efid1 = 0xFFFFFF0;
    extendedFilter.efec = kMCAN_storeinFifo0;
    extendedFilter.efid2 = 0xFFFFFFF;
    extendedFilter.eft = kMCAN_disableORrange2;
    MCAN_SetEXTFilterElement(EXAMPLE_MCAN, &rxFilter, &extendedFilter, 0);

    /*Second filter configuration*/
    extendedFilter.efid1 = 0x1;
    extendedFilter.efec = kMCAN_storeinFifo0;
    extendedFilter.efid2 = 0xF;
    extendedFilter.eft = kMCAN_disableORrange2;
    MCAN_SetEXTFilterElement(EXAMPLE_MCAN, &rxFilter, &extendedFilter, 1);

With this condiguration I set two ranges, one for 0xFFFFFF0 - 0xFFFFFFF, and the other for 0x1 - 0xF, check that the last parameter in the MCAN_SetEXTFilterElement is the filter offset, with this you change where is stored this filter.

I hope this helps you.

Best Regards,

Alexis Andalon

在原帖中查看解决方案

3 回复数
4,503 次查看
Alexis_A
NXP TechSupport
NXP TechSupport

Hi Manikanta,

If you already have a working example about it, check the 35.15 section of the reference manual, here you can set the filter ID, select where the mesages would be stored and the filter configuration.

pastedImage_1.png

pastedImage_2.png

If you're using the SDK, you could try with the following code:

    extendedFilter.efid1 = 0xFFFFFF0;
    extendedFilter.efec = kMCAN_storeinFifo0;
    extendedFilter.efid2 = 0xFFFFFFF;
    extendedFilter.eft = kMCAN_disableORrange2;
    MCAN_SetEXTFilterElement(EXAMPLE_MCAN, &rxFilter, &extendedFilter, 0);

Here the filter is set to range, so the messages between 0xFFFFFF0 and 0xFFFFFF would be received.

I hope this helps you.

Best Regards,

Alexis Andalon

0 项奖励
回复
4,503 次查看
gmk1
Contributor III

Hey Alexis, 

thanks for the reply. I got to that point already. Please see the code snippet below. It has a statement <rxFilter.listSize = 1U>

Can you tell me what is it used for? What happens if I increase the list size?

/* global filter config */

   rxFilter.address = STD_FILTER_OFS;

   rxFilter.idFormat = kMCAN_FrameIDStandard;

   rxFilter.listSize = 1U;

   rxFilter.nmFrame = kMCAN_reject0;

   rxFilter.remFrame = kMCAN_rejectFrame;

   MCAN_SetFilterConfig(EXAMPLE_MCAN, &rxFilter);

0 项奖励
回复
4,504 次查看
Alexis_A
NXP TechSupport
NXP TechSupport

Hi Manikanta,

This parameter is used to enable more than one filter, if you want to set more than one filter, for example, in the next code:

 /* STD filter config. */
    rxFilter.address = STD_FILTER_OFS;
    rxFilter.idFormat = kMCAN_FrameIDExtend;
    rxFilter.listSize = 2U;
    rxFilter.nmFrame = kMCAN_reject0;
    rxFilter.remFrame = false;
    MCAN_SetFilterConfig(EXAMPLE_MCAN, &rxFilter);

    /*First filter configuration*/
    extendedFilter.efid1 = 0xFFFFFF0;
    extendedFilter.efec = kMCAN_storeinFifo0;
    extendedFilter.efid2 = 0xFFFFFFF;
    extendedFilter.eft = kMCAN_disableORrange2;
    MCAN_SetEXTFilterElement(EXAMPLE_MCAN, &rxFilter, &extendedFilter, 0);

    /*Second filter configuration*/
    extendedFilter.efid1 = 0x1;
    extendedFilter.efec = kMCAN_storeinFifo0;
    extendedFilter.efid2 = 0xF;
    extendedFilter.eft = kMCAN_disableORrange2;
    MCAN_SetEXTFilterElement(EXAMPLE_MCAN, &rxFilter, &extendedFilter, 1);

With this condiguration I set two ranges, one for 0xFFFFFF0 - 0xFFFFFFF, and the other for 0x1 - 0xF, check that the last parameter in the MCAN_SetEXTFilterElement is the filter offset, with this you change where is stored this filter.

I hope this helps you.

Best Regards,

Alexis Andalon