![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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. 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 |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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... |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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 .... |
|
|
|
|
|
|
(permalink) |
|
How do you know that the filters are not working?
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Thaks Alot for help me... |
||
|
|
|
|
|
(permalink) |
|
All you ever need to know is contained in the datasheet.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
Thanks a lot,
Im a goofy, Now i begin new project, a rs232 to CAN, do you have a tips for me ???? thanks again!!! |
|
|
|
|