|
|
View previous topic :: View next topic |
Author |
Message |
naughty_mark
Joined: 29 Aug 2012 Posts: 97
|
Question about CAN bus filter |
Posted: Tue Oct 09, 2012 11:40 pm |
|
|
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
|
|
Posted: Wed Oct 10, 2012 4:13 am |
|
|
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
|
|
|
naughty_mark
Joined: 29 Aug 2012 Posts: 97
|
|
Posted: Wed Oct 10, 2012 3:07 pm |
|
|
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 |
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. 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: 1907
|
|
Posted: Thu Oct 11, 2012 10:09 am |
|
|
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. |
|
|
|
|
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
|