|
|
View previous topic :: View next topic |
Author |
Message |
RickMarsen
Joined: 31 Oct 2008 Posts: 17
|
ECAN Filtering Theory - Range of IDs |
Posted: Wed Feb 24, 2010 9:24 pm |
|
|
I am wondering if anyone has successfully set up a filtering scheme whereby a range of IDs are allowed through.
Using this code I am able to filter out all but the two specified IDs (100 and 200) but I haven't mastered how to turn these "features" into a filter that allows through a range of IDs.
I understand the masks are applied such that "1"s in the mask require the corresponding bit in the incoming ID to match the same bit in either of the filters and that 0s in the mask allow all ID bits in those locations to be accepted.
I don't really understand the role of the second mask nor the four filters it's supposed to be applied to.
I am using a 18F4685 @40MHz, 500kB and 11-bit IDs (i.e. not extended). Everything works quite nicely otherwise.
Code: | can_set_mode(CAN_OP_CONFIG);
can_set_id(RX0MASK,0xFFFF,CAN_USE_EXTENDED_ID);
can_set_id(RX0FILTER0,0x100,CAN_USE_EXTENDED_ID);
can_set_id(RX0FILTER1,0x200,CAN_USE_EXTENDED_ID);
//can_set_id(RX1MASK,0xFFFF,CAN_USE_EXTENDED_ID);
//can_set_id(RX1FILTER2,300,CAN_USE_EXTENDED_ID);
//can_set_id(RX1FILTER3,400,CAN_USE_EXTENDED_ID);
//can_set_id(RX1Filter4,500,CAN_USE_EXTENDED_ID);
//can_set_id(RX1Filter5,600,CAN_USE_EXTENDED_ID);
can_set_mode(CAN_OP_NORMAL); |
If anyone can shed any light on the functinality of the ECAN module filtering/masking wrt to the above, it would be much appreciated.
Rick |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Thu Feb 25, 2010 7:18 am |
|
|
RX0 mask and filters apply to packets that will end up in the RX0 buffer. Similar to the RX1 items. Note that the CCS CAN library just has a single "get" function that checks buffer 0 then buffer 1 and returns the first packet it finds. It makes it look as if there is only one buffer.
You effectively have two masks and filters for the one apparent receive buffer.
Now, lets say you want to only receive packets with an ID in the range of 0x100 through 0x1FF inclusive. That's easy. The mask is 0xFF00 and the filter is 0x0100. If you also wanted 0x300 through 0x3FF, then a second filter would be 0x0300. Packets for both ranges will end up in the same receive buffer.
However, if you also wanted 0x450 through 0x45F, then the 0xFF00 mask is no good. That's where the second mask comes in handy. The mask and filter would be 0xFFF0 and 0x0450 respectively. These packets end up in the second receive buffer, but as pointed out, the CCS get function checks both buffers in turn. _________________ Andrew |
|
|
RickMarsen
Joined: 31 Oct 2008 Posts: 17
|
|
Posted: Thu Feb 25, 2010 11:40 pm |
|
|
Andrew,
THANK YOU VERY MUCH for that excellent explanation.
I still had a bit of trouble figuring out why it wasn't working even after implementing your suggestion. The reason was that (unless you set the second mask (RX1MASK) to 0xFFFFFFFF at the same time you set the first mask (RX0MASK) and its two filters), all CAN traffic will continue to come through via buffer 1 as RX1MASK is initialized to zero on power-up and so accepts all incoming IDs.
Rick |
|
|
|
|
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
|