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

CANBus ID filtering
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PostPosted: Sun Aug 05, 2007 12:15 am     Reply with quote

I'm a little confused with the filtering, I have played with CAN based on the examples but I made my own filtering system that only listens to messages with the devices ID on it (and a broadcast ID). It was a system thrown together for the company I work for.

How exactly would I gain the same effect using the can_set_id commands?

I used extended ID's btw.
It is set up like so:
Code:

#define my_id 0x11 // my ID
int1 tx_rtr=0; // was 1
int1 tx_ext=1; // was 0
int tx_len=8;
int tx_pri=3;
byte outdata[8];
int rx_len;
int i;


I also have can_init() in the main function before I go into the main loop.

then when in the main() loop I poll the can_kbhit() check the ID attached to it and only accept if it matches my_id or broadcast (0xFF)

Say, one unit is id 0x11 and broadcast is 0xFF, I want unit 0x12 to send a message with the ID of 0x13. how would I counfigure the code below to ignore any message that is not addressed to ID 0x11 or 0xFF?

Code:

  can_set_id(RX0MASK, 0x07FFFFFFF, CAN_USE_EXTENDED_ID);  //set mask 0
   can_set_id(RX0FILTER0, 0x0074, 1);  //set filter 0 of mask 0
   can_set_id(RX0FILTER1, 0x0074, 1);  //set filter 1 of mask 0

   can_set_id(RX1MASK, 0x07FFFFFFF, CAN_USE_EXTENDED_ID);  //set mask 1
   can_set_id(RX1FILTER2, 0x0074, 1);  //set filter 0 of mask 1
   can_set_id(RX1FILTER3, 0x0074, 1);  //set filter 1 of mask 1
   can_set_id(RX1FILTER4, 0x0074, 1);  //set filter 2 of mask 1
   can_set_id(RX1FILTER5, 0x0074, 1);  //set filter 3 of mask 1

note: this code was taken from the other page of this thread.

also, would can_kbhit() and the can interupts ignore the non-addressed packets?

many thanks
ferrumvir



Joined: 01 Feb 2006
Posts: 64
Location: England

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 05, 2007 2:04 pm     Reply with quote

Code:

can_set_id(RX0MASK, 0x07FFFFFFF, CAN_USE_EXTENDED_ID);  //set mask 0
   can_set_id(RX0FILTER0, 0x0011, 1);  //set filter 0 of mask 0
   can_set_id(RX0FILTER1, 0x00FF, 1);  //set filter 1 of mask 0

   can_set_id(RX1MASK, 0x07FFFFFFF, CAN_USE_EXTENDED_ID);  //set mask 1
   can_set_id(RX1FILTER2, 0x00FF, 1);  //set filter 0 of mask 1
   can_set_id(RX1FILTER3, 0x00FF, 1);  //set filter 1 of mask 1
   can_set_id(RX1FILTER4, 0x00FF, 1);  //set filter 2 of mask 1
   can_set_id(RX1FILTER5, 0x00FF, 1);  //set filter 3 of mask 1 



The above code should set the chip up to recieve only the two IDs of interest. Have a look at a mistake I was making in this http://www.ccsinfo.com/forum/viewtopic.php?t=30984 thread if you want a little more insight.
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PostPosted: Sun Aug 05, 2007 6:42 pm     Reply with quote

many thanks, I will try this tommorow when I get a chance.
Guest








PostPosted: Sat Dec 08, 2007 4:17 pm     Reply with quote

ferrumvir: you mentioned you made a mistake, and it was the parameters list thing, did this allow you to filter different rxID's when you fixed it?

Code:
void can_filt( int16 rxid1,rxid2,rxid3,rxid4,rxid5,rxid6 )
{
   can_set_mode(CAN_OP_CONFIG);

   can_set_id(RX0MASK, 0x07FF, 0);    //set mask 0 // MATCH MASK 100%
   can_set_id(RX0FILTER0, rxid1, 0);  //set filter 0 of mask 0
   can_set_id(RX0FILTER1, rxid2, 0);  //set filter 1 of mask 0

   can_set_id(RX1MASK, 0x07FF, 0);    //set mask 1 // MATCH MASK 100%
   can_set_id(RX1FILTER2, rxid3, 0);  //set filter 0 of mask 1
   can_set_id(RX1FILTER3, rxid4, 0);  //set filter 1 of mask 1
   can_set_id(RX1FILTER4, rxid5, 0);  //set filter 2 of mask 1
   can_set_id(RX1FILTER5, rxid6, 0);  //set filter 3 of mask 1

   can_set_mode(CAN_OP_NORMAL);
}


this is your code from the linked thread, did it work when you changed the parameter list? also, does this allow you to select which rxID's to listen to?

thanks
ferrumvir



Joined: 01 Feb 2006
Posts: 64
Location: England

View user's profile Send private message Visit poster's website

PostPosted: Sun Dec 09, 2007 1:36 pm     Reply with quote

Once the parameter list for the function call was fixed, i.e. declaring each int16 the routine worked fine.

All the rxids come in to the can_kbhit or the interupts, you need to parse out which ID is being handled and handle it accordingly.

Hope that helps.

Cheers Scott
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PostPosted: Tue Jan 29, 2008 9:09 pm     Reply with quote

I got my code working in the end,
I set the RX0 filters to 0x0011 (which is the boards ID) and the RX1 filters to 0x00FF (which is the broadcast ID) and using the separate RX0 and RX1 interrupts I have a separate interrupt for a direct addressed packet and broadcast packet.

on a side note, do you know if I can change the filters or even the speed of the CAN at run-time? I am designing a new system with a faster rate CAN and I want to be able to be able to use my CAN-RS232 module with both systems and select the speed via my PC software?

many thanks

Peter
ferrumvir



Joined: 01 Feb 2006
Posts: 64
Location: England

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 05, 2008 10:29 am     Reply with quote

Hi RatGod,

Yes you can reconfigure the speed at run time though you have to take the bus off line, use the can_set_mode function to take the bus off and on line and set the speed inbetween. Sorry I've not got access to my code so I can't tell you what the speed related registry settings are. Have a look in the example can_init() function.

Code:

  can_set_mode(CAN_OP_CONFIG);
  // SET SPEED HERE
  can_set_mode(CAN_OP_NORMAL);


Cheers Scott
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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