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

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

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

Jump to solution
2,611 Views
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

Labels (3)
1 Solution
2,291 Views
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

View solution in original post

3 Replies
2,291 Views
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 Kudos
2,291 Views
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 Kudos
2,292 Views
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