2009/11/03 00:44:36
ram_varpe
Hi ,
        i have 1 dsPIC33f CAN board(Master) and i want 7 other dsPIC33f controller to be connected to other end through CAN.For Master to 7 nodes i am broadcasting my message but while receiving data from 7 nodes i have confusion in setting Mask and Filter values.My message id for 7 nodes are 1,2,3...7 ,Can you help me for setting Mask and Filter register values.
2009/11/03 04:34:29
Artic
Hi,
I suggest you read the following comments with the CAN2.0A/B spec open in front of you, and a copy of the dsPIC CAN reference document (from Microchip).

Important Fact 1: Do not think that a CAN ID is a "number". It is a collection of bits that are used to prioritize a CAN message on a CAN bus.
Important Fact 2: Do not think that an Rx Mask is a "number", this also is just a collection of bits that enable or disable matching bits in the Rx filter,
Important Fact 3: Do not think that an Rx Filter is a "number", this is also just a collection of bits that the CAN engine will use during the message receive process.

(now would be a good time to re-read the CAN 2.0A/B and Microchip documents about Filters & Masks)

To answer your question (I am using STD ID addressing to keep things simple)...
i have confusion in setting Mask and Filter values.My message id for 7 nodes are 1,2,3...7
First apply what you now understand about CAN Ids (remember ID's are only a collection of bits).
Take your first CAN message ID (1). In reality, this ID is actually sent on the CAN bus as a series of bits "00000000001", your CAN message ID (2) is actually sent as "00000000010".
Ok, for a CAN node to correctly receive these messages, the message needs to "pass" the CAN node Rx filter.

Example 1:
How to set a CAN node Rx Mask and Filter to only receive CAN ID 1 and not CAN ID 2?
Remember, think of the ID as a bit-filed (which it is), and convert the ID into binary (makes things easy if you do).
ID: 1 = 00000000001
ID: 2 = 00000000010

Ok, now (from your reading of the CAN2.0A/B spec) you will know that the Mask is like a switch to enable/disable bits of the Rx filter. As it is the filter that actually does the work, the first thing you should do is set the scope of the filter. So for your CAN node to only receive CAN ID 1, you want your filter to match this requirement.
FilterA = 00000000001

Now set the Mask to enable the bits of the filter you want to check the CAN ID against. In our case, we will set the Mask to ensure the filter will only pass CAN frames with an ID of 1.
Mask = 11111111111 (All 1's means that each bit of the Rx filterA will be used to check the incoming CAN frame ID against.



Example 2:
If you want set the filter to receive a number of (sequential) CAN frame IDs, then all you need to do is set some of the bits in the Mask & Filter to 0.

I want to receive CAN Frame ID's 1,2 & 3, but I don't want to receive CAN frame ID 4
Again, it is always easier to break down the task into binary (until you understand the process).
ID1 = 00000000001
ID2 = 00000000010
ID3 = 00000000011
ID4 = 00000000100

This time, first set the filter Mask to ignore the bits of the ID that are common with all the wanted IDs - in this example, set the Mask bits 0,1 = 0. This will cause the filter to ignore the two lsb bits of the CAN ID.
Mask = 11111111100

Second, set the filter to "match" the common bits of the CAN IDs you want.
FilterA = 00000000000

When you combine the Mask and filter you will see that you have created (what I call) an "Rx Rule".
Mask = 11111111100
FilterA = 00000000000
IDs that will be accepted: 1,2,3
IDs that will be rejected: 4 to 2047

Hope some of it helps
Artic
2012/03/27 09:34:27
blotfib


Thanks for you clear Message
The microchip eCAN PDF Example 21-4: Code Example for Filtering Standard Data Frame
is not clear at all !
One can not see the use of mask for filtering multiple messages ID with the same filter
Best regards

2012/06/01 01:50:05
loralein
Hi i do have somme Problem with setting  filter and mask for an extended frame on dsPIC30F4013
i want to receive this ID:0x18FF0D82 (SID =0x63F and EID = 0x30D82)
c1rxm0sid=0x1FFD
c1rxm0sidbits.mide=1
c1rxm0eidh = 0x0FFF
c1rxm0eidl=0xFC00
 
r1rxf0sid =0x18FC
c1rxf0sidbits.exide =1
c1rxf0eidh=0x0C36
c1rxf0eidl=0x0800
It didnt receive anything.. do i have wrong settings ?? or must i set it as binary not hex ?
 
Kind regards
 

2015/09/11 05:38:07
Bremenpl
Hello there,
I have the exact same problem here with dsPIC4011. I am following this topic as well as many others but I still cannot make this filter to work.
This is my initialization:
void CanInit()
{
    unsigned int adr_sid1;
    unsigned long  adr_eid1;

     // Set request for configuration mode
    C1CFG1 = 0;
    C1CFG2 = 0;
    DisableIntCAN1;

    //C1CTRL
    CAN1SetOperationMode(CAN_IDLE_CON  &
                         CAN_MASTERCLOCK_0 &
                         CAN_REQ_OPERMODE_CONFIG &
                         CAN_CAPTURE_DIS);

    while(C1CTRLbits.OPMODE <=3);

    C1CFG2 =0x02A0; //1m 20Mhz


    CAN1SetFilter(0,
             CAN_FILTER_SID(1) &      // The SID to match
             CAN_RX_EID_EN,           // Enable EID filtering
             CAN_FILTER_EID(0));      // The EID to match

    CAN1SetFilter(1,
             CAN_FILTER_SID(1) &      // The SID to match
             CAN_RX_EID_EN,           // Enable EID filtering
             CAN_FILTER_EID(0));      // The EID to match

    CAN1SetMask (0,
             CAN_MASK_SID(0x7FE) &
             CAN_MATCH_FILTER_TYPE,
             CAN_MASK_EID(0x3FFFF));
*/
    /* Set transmitter and receiver mode */
    CAN1SetTXMode(0,
                  CAN_TX_STOP_REQ &
                  //CAN_TX_REQ &
                  CAN_TX_PRIORITY_HIGH );
    CAN1SetRXMode(0,
                  CAN_RXFUL_CLEAR &
                  CAN_BUF0_DBLBUFFER_EN);

    ConfigIntCAN1(CAN_INDI_INVMESS_EN &
                CAN_INDI_WAK_DIS &
                CAN_INDI_ERR_EN &
                CAN_INDI_TXB2_DIS &
                CAN_INDI_TXB1_DIS &
                CAN_INDI_TXB0_DIS &
                CAN_INDI_RXB1_EN &
                CAN_INDI_RXB0_EN ,
                CAN_INT_PRI_3 &
                CAN_INT_ENABLE);

    CAN1SetOperationMode(CAN_IDLE_CON  &
                         CAN_MASTERCLOCK_0 &
                         CAN_REQ_OPERMODE_NOR &
                         CAN_CAPTURE_DIS);
    while(C1CTRLbits.OPMODE>0);

    SetPriorityIntCAN1(1);
    EnableIntCAN1;
}                        

What I am trying to do here is to simply accept only the frames with ID 1 (just for test because I am trying this config for ages to work). Even though, I am not receiving any messages now, even with ID 1. What am I configuring wrong? I cannot solve this for a whole day now. I would really apreciate all help!
2017/03/27 13:55:00
nigelwright7557
I have read a few articles on masks and filters.
They all say use 1's to let through bits you want in the mask and 0's to ignore other bits.
It doesn't work on my setup at all.
I seem to need 0's in the mask to let things through not 1's.
If I set mask to all 0's and acceptance filter all 0's then things pass through OK.
 
2017/03/27 14:05:01
CinziaG
Working on a PIC24GU these days, and definitely "1" activate a filter while "0" lets everything get through Smile
2017/03/27 15:13:27
nigelwright7557
I found out that the reason my mask and acceptance filter weren't working was because I was setting the EXIDE bit.
If I leave it reset they work as expected.
I was just filling acceptance filter with 0ffh which also set EXIDE bit.
 
2018/04/20 12:40:34
Trevor Smith
Hi All,
Having problems with acceptance filters.
Just found Artic's excellent explanation above .... thanks Artic.
So, working on a CAN project with 3 Nodes .......
Node 1 = ID1
Node 2 = ID2
Node 3 = ID3
 
Node 1 rejects it's own transmissions OK.
Node 2 rejects it's own transmissions OK.
How can I set acceptance filters and masks, to make Node 3 reject it's own transmissions ?
 
I've tried code in Node 3 which tests RXB0EID:RXB0EIDL and so will ignore ID3, but it seems to slow Node 3 down, compared to the other nodes.
 
Help please.
Trevor
© 2020 APG vNext Commercial Version 4.5

Use My Existing Forum Account