CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Question about CAN bus filter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

Question about CAN bus filter
PostPosted: Tue Oct 09, 2012 11:40 pm     Reply with quote

Hi, there,

I am using ds33PICEP256MU814 microchip and CCS version 4.133.
Currently I am doing CAN bus filter code, and got some problem, it looks I can not block the CAN ID message I want, it always leak and put those unwanted message in to FIFO.

my CAN bus initialization code is below:
Code:

   can_set_mode(CAN_OP_CONFIG);   //must be in config mode before params can be set

   C1CTRL1.cancap=CAN_ENABLE_CAN_CAPTURE;
   C1CTRL1.cancks=0;
   can_set_baud();

   can_set_buffer_size(CAN_BUFFER_SIZE);      // sets size of DMA buffer to use
   can_config_DMA();

   can_set_id(&C1RXM0, CAN_MASK1, CAN_USE_EXTENDED_ID);  //set mask 0
   can_set_id(&C1RXM1, CAN_MASK2, CAN_USE_EXTENDED_ID);  //set mask 1
   can_set_id(&C1RXM2, CAN_MASK3, CAN_USE_EXTENDED_ID);  //set mask 2
//
//   // set dynamic filters
   can_set_id(&C1RXF0, FILTER_FEE_GROUP, CAN_USE_EXTENDED_ID);
   can_set_id(&C1RXF1, FILTER_FEF_GROUP, CAN_USE_EXTENDED_ID);
   can_set_id(&C1RXF2, FILTER_PGN_F003, CAN_USE_EXTENDED_ID);
   

   can_associate_filter_to_mask(ACCEPTANCE_MASK_0,F0BP); //mask 0 is for filter0 to filter PGN 65251 to 65263
   can_associate_filter_to_mask(ACCEPTANCE_MASK_1,F1BP); //mask 1 is for filter1 to filter PGN 65264 to 65271

   can_associate_filter_to_mask(ACCEPTANCE_MASK_2,F2BP); //mask 3 is for rest of PGN

   
   C1FEN1=0;

   can_associate_filter_to_buffer(AFIFO,F0BP);
   can_associate_filter_to_buffer(AFIFO,F1BP);
   can_associate_filter_to_buffer(AFIFO,F2BP);



   can_enable_filter(FLTEN0);
   can_enable_filter(FLTEN1);
   can_enable_filter(FLTEN2);
 

   can_set_mode(CAN_OP_NORMAL);


what I am trying to do is mask1 for filter0, mask2 for filter1, both of them can identify two kinds of group IDs, and mask3 is for filter2 which is just for one certain ID, for example 0x18FBCA00.
However, if I tried to set one of them, such as filter2 to other value which should give me the result that 0x18FBCA00 would blocked, it failed.
I think there must be some points I don't get it about CAN bus filter setting, can someone help or any suggestions?

Kind Regards
Mark
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 4:13 am     Reply with quote

To be honest, I do a bit of CAN stuff, and try to help on CAN queries, but you already seem to be doing pretty advanced stuff, and I'd be tempted to be looking to you for answers rather than the other way round!

Are you using the ECAN in one of the extended modes (not extended ID, the extended operating modes, such as FIFO)? If so you are well beyond many of us.

I personally find the OR-AND masking arrangements (somewhat like TCP/IP masking) to be difficult to get my head around, and the ECAN documentation to not quite tell the whole story, at least, not always in a clear way.

In short, I suspect you're on your own on this one. When you get it sussed, please fell free to come back and be the new CAN guru!

RF Developer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 12:19 pm     Reply with quote

This Microchip training document gives a good explanation of how the
CAN bus message reception filters and masks work (starting on page 14):
http://www.microchip.com/stellent/groups/SiteComm_sg/documents/Training_Tutorials/en528354.pdf
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

PostPosted: Wed Oct 10, 2012 3:07 pm     Reply with quote

RF_Developer wrote:
To be honest, I do a bit of CAN stuff, and try to help on CAN queries, but you already seem to be doing pretty advanced stuff, and I'd be tempted to be looking to you for answers rather than the other way round!

Are you using the ECAN in one of the extended modes (not extended ID, the extended operating modes, such as FIFO)? If so you are well beyond many of us.

I personally find the OR-AND masking arrangements (somewhat like TCP/IP masking) to be difficult to get my head around, and the ECAN documentation to not quite tell the whole story, at least, not always in a clear way.

In short, I suspect you're on your own on this one. When you get it sussed, please fell free to come back and be the new CAN guru!

RF Developer


Shocked thanks for your compliment RF_Developer, and thanks for your document PCM programmer, I will read it soon. Actually, the code is provided by ccs, all the functions are not built by myself, I just use them. Wink and I just use extended ID, I am not sure what is "extended mode" you mentioned.
What my understanding of CAN filter in PIC is, you set mask in mask0, mask1 and mask2(depending on how much you wanna use), and set filter, and associate mask with filters. Then tell PIC once those msg matches with one of the filter, which rx buffer you wanna it put in, which called "buffer associate with filter", then enable the filter you want. So once a message coming in, it will go through each enabled filter and once it matches, as my code showed, the message will put into the buffer(FIFO) and set a flag to trigger an interrupt or let main program knows..But it just doesn't work yesterday, the unwanted message keep leak in.
Anyway, I will read the document and see if I can figure it out.
Thanks for your help, and if anyone has idea or suggestion on this topic, please let me know, thanks~
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Thu Oct 11, 2012 10:09 am     Reply with quote

Code:
   // mask bit n | filter bit n | message ID bit n | result
   //     0             x               x             accept
   //     1             0               0             accept
   //     1             0               1             reject
   //     1             1               0             reject
   //     1             1               1             accept


This little reminder goes in every can_init() function I write.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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