Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to apply a filters and mask ond CAN Bus controller MCP2515

Status
Not open for further replies.

rafaelvg

New Member
Hello,

I would like to implement on a Controller Area Network (CAN) a filters and masks to select which device will take the messages. But i don´t know how to begin.:mad: :mad: :mad: :mad:
The problem is... when i send message to the can bus all devices read the message, but i would like to make a filter for just the target device take the message from CAN bus.

Tks :) :)
Rafael V. Gonçalves
 
Mask and Match filters are simple to apply. You take the mask and use it to select bits from the identifier field(either 11 for standard frame or 29 for extended frame) Bits in the identifier are either don't care(can be a 1 or a 0), or they are "must match" and must be equal to the value of the bit in the match register. So if node address is contained in the CAN Identifier field then it is a piece of cake to filter out just the messages inteded for this node.

For reasons which must be altogether clear, no two nodes on a CAN network are allowed to transmit the same identifier. This would lead to arbitration problems if they both started transmitting at the same time. There would most likely be a bit error as soon as the data field was transmitted, a bit error would be detected and the transmitter would throw an error frame causing everybody else to throw an error frame.

Good Luck
 
Thanks friend...

I´m using a MCP2515...The filter and the mask is edit on MCP2515.c ??? or in the main() program????

Thank you for reply... :D :D
 
The hardware chip does not care where or how you set up those registers. Generally speaking you want to set up the mask and match filters during the one time initialization before you bring the CAN controller out of RESET.

The Philips SJA 1000 CAN Controller even prevents you from changing the mask and match filter registers while the chip is in normal operation. I'm not that familiar with the Microchip part, but that sure seems like a good idea.
 
thank you again Papabravo,


I set my mask and filter like this:

mcp2510_init();

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

b_rxb0ctrl=0;
b_rxb0ctrl.rxm=CAN_RX_VALID;
b_rxb0ctrl.bukt=CAN_USE_RX_DOUBLE_BUFFER;
mcp2510_write(RXB0CTRL, (int)b_rxb0ctrl);
mcp2510_write(RXB1CTRL, (int)b_rxb0ctrl);

//if you want to configure the TXnRTS pins, do it here. default is off
mcp2510_write(RXM0SIDH, (int)0x07FF);
mcp2510_write(RXM0SIDL, (int)0x07FF);
mcp2510_write(RXM0EIDH, (int)0x07FF);
mcp2510_write(RXM0EIDL, (int)0x07FF);
mcp2510_write(RXF0SIDH, (int)0x07FF);
mcp2510_write(RXF0SIDL, (int)0x07FF);
mcp2510_write(RXF0EIDH, (int)0x07FF);
mcp2510_write(RXF0EIDL, (int)(0x07FF1);


can_set_mode(CAN_OP_NORMAL);//CAN_OP_LOOPBACK
}


but the filters don´t work correct ....
 
How do you know that the filters are not working?
 
Papabravo said:
How do you know that the filters are not working?

I´m using SIMPLEHID program to send packages from computer to CAN BUS, I solve the problema, but now i just apply FILTER 0 and FILTER 1 from MASK0 on buffer0...Which register i will need to set for accept mask1 and other filters???

Thaks Alot for help me...
 
All you ever need to know is contained in the datasheet.
 
The mask register divides the bits in the CAN identifier and data field into two categories. Those are don't care and must match. A bit which is don't care can be either a 1 or a 0. A bit which is must match must be equal to the value in the corresponding position of the match register.

For example, if you are using 11-bit identifiers and you want the most significant bits(10 and 9) to be equal to "10" then you set the mask register for those bits to "must match" and you set the match register for thos bits to "10"

You particular chip may have multiple filters. In that case a receive frame gets through if it satifies any of the mask and match conditions.

As a final note your first experiments in CAN should operate in promiscuous mode where you let everything through. Later when you have receive and transmit working you can apply the filters to lessen the load on an individual node.
 
Thanks a lot,

Im a goofy, :p :p :p :p , I invert the lsb in the filter values , they work properly but not with the values i think the have to work, now i solve the problem....
Now i begin new project, a rs232 to CAN, do you have a tips for me ???? :D :D


thanks again!!!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top