![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
mkkirchner
Joined: 30 Dec 2010 Posts: 3
|
CAN Filter and Mask |
Posted: Sat Jan 08, 2011 6:54 am |
|
|
Hi,
I try tu setup a small CAN-Network with some 18F2585.
The main functions are all O.K. I have tested it with CANAlyzer (Vector), and it looks good.
But no I will configure sime ID Filter, but I did not understand the filter and mask settings in the CCS files.
So I have a event : "can_kbhit()" This event should be triggerd only if a CAN Messages available which passed teh filter ( I am right ??)
Now I have to Maskes and 6 Filters:
From the original CCS file
Code: | can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, CAN_USE_EXTENDED_ID); //set mask 0
can_set_id(RXFILTER0, 0, CAN_USE_EXTENDED_ID); //set filter 0 of mask 0
can_set_id(RXFILTER1, 0, CAN_USE_EXTENDED_ID); //set filter 1 of mask 0
can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, CAN_USE_EXTENDED_ID); //set mask 1
can_set_id(RXFILTER2, 0, CAN_USE_EXTENDED_ID); //set filter 0 of mask 1
can_set_id(RXFILTER3, 0, CAN_USE_EXTENDED_ID); //set filter 1 of mask 1
can_set_id(RXFILTER4, 0, CAN_USE_EXTENDED_ID); //set filter 2 of mask 1
can_set_id(RXFILTER5, 0, CAN_USE_EXTENDED_ID); //set filter 3 of mask 1 |
So I can configure every of the 6 Filters with any of the 2 masks (??)
But this I do not understand!!
How I have to configure The Filters and Masks to release the can_kbhit() event only by messages with the IDs 220-229 and the ID 50 (for sample)
Can any body explain me this filter and mask functions?? Or can give my a link to some informations??
Thanks a lot for your help!!
Martin |
|
![](templates/subSilver/images/spacer.gif) |
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
Re: CAN Filter and Mask |
Posted: Sat Jan 08, 2011 9:40 am |
|
|
mkkirchner wrote: |
So I have a event : "can_kbhit()" This event should be triggerd only if a CAN Messages available which passed teh filter ( I am right ??)
|
Yes, it returns true if a message has gotten through the filters and is now waiting to be read by you.
Quote: |
Now I have two Masks and 6 Filters:
From the original CCS file
<SNIP CODE>
So I can configure every of the 6 Filters with any of the 2 masks (??)
But this I do not understand!!
|
There are three modes of operation: Legacy, Enhanced, FIFO. You are most likely in legacy mode as that's what the driver defaults to. In legacy mode filters 0 and 1 are associated with mask 0 and filters 2-5 are associated with mask 1. You can't change that.
Quote: |
How I have to configure The Filters and Masks to release the can_kbhit() event only by messages with the IDs 220-229 and the ID 50 (for sample)
Can any body explain me this filter and mask functions?? Or can give my a link to some informations??
|
Hopefully I'm not totally completing your homework or something but I'll explain the whole thing at any rate so hopefully you see how it works:
Masks and filters work like this - First your mask is AND (binary operation) with the id of the incoming frame. Then this value is compared to each filter. If the value matches a filter then the frame goes through. This is done for all masks and all filters until there is either a match or their isn't.
In the first part of your example you want to allow 220-229. Lets look at the bit pattern for those IDs:
220 = 11011100
221 = 11011101
222 = 11011110
223 = 11011111
224 = 11100000
225 = 11100001
226 = 11100010
227 = 11100011
228 = 11100100
229 = 11100101
To find a decent mask you need to figure out what your ids have in common and which bits might be important in order to create a filter. You only have so many filters so you've got to be choosy. You have some choices here. You could start by looking at how the ids all have bits 6 and 7 set.
So you could create a mask of 11000000 and a filter of 1100000. Let me show you how this would work:
Let's say you have a frame incoming with an ID of 223. That's 11011111. If you AND that with 11000000 (mask) you will get an answer of 11000000. If you compare 11000000 with the filter value of 11000000 you will see that they are the same. So, it passes the filter and will be accepted.
You might, however, see that a lot of other values would pass the filter as well. You can either live with that or you can try to create a more choosy mask and filter combo. That will be difficult as your choice of example ids has a lot of variation in bit patterns. But, lets say you want to narrow it down a bit more. If you use both masks then you can see that there are two distinct bit patterns. One starts with 110111 and one starts with 11100. So let's create two masks. One will be 11011100 and the other 11111000. For the first mask anything that matches 11011100 is OK so it needs only one filter: 11011100. The second mask will also have only one filter. This filter will be different than the mask though. This filter is 11100000. Hopefully you can see why. This setup will be much more choosy but still lets through some unwanted ids.
To allow a single ID through you just set a mask and filter to the exact bit patter of the ID to let through. So both mask and filter would be 50 (00110010). |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|