-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with setting Filter and Mask during bus traffic #7
Comments
I have built this up and I can replicate what you are experiencing. I have found that if I hold the reset button for a good five seconds while connected to a utilized bus, the filtering appears to behave as I would expect it to... I am not sure what the issue is, but I have been trying to work with Microchip about masks and filtering for a different but similar issue. In the mean time, I would also suggest that you use an 'if/then' statement to check the received ID against 0x20A in your sketch. Additionally, I previously told you to use 0x3FF for the mask, that was a mistake on my part and it should be 0x7FF but that has no burden on the above issue. |
I may have found a solution! I have a fork of this library on my github. I started a sub-development branch that allows the sketch to change the mode of the MCP2515. I modified a local copy of that library to initialize the MCP2515 while in 'loopback mode,' setup the masks and filters, and then I put it into 'normal mode.' Since trying this, I have not been able to recreate your problem. I will push my modifications to it in a moment... |
Thank you. I can test your sub-development in a few days (my boards are at home and I am still on holiday), maybe on thursday or friday. I will report directly the results. Thank you for working on library. |
At the moment, I am testing your sub-development. I had to modify some things like 'begin': CAN.begin(MCP_STD, CAN_500KBPS, MCP_16MHZ) and I changed the ID reading method according to your lib changes. I have replaced the following three files: mcp_can.cpp, mcp_can.h and mcp_can_dfs.h While building, there was an error with CAN_31K25BPS (not declared). I removed the case: CAN_31K25BPS in mcp_can.cpp and no further errors appeared. The Problem: No IDs are filtered. Every ID comes in. At the moment, I do not know where to search the error. In your master branch ID filtering works (if there is no big bus traffic). |
Did you also change the way the masks and filters are used? Standard IDs would be entered like 0x7FF0000 for the mask and 0x20A0000 for the filters. This change was to increase the functionality of the library. The MCP2515 can also filter the first two data bytes of standard ID messages. I'm going to correct the CAN_31K25BPS error now, thanks for mentioning it. |
Hi, I'm using your fork, But I have same probleme to init mask. I want to get 0x613 ID only, I tried this code, but i got return to previous mod failure, init mask failure : ` #include <mcp_can.h> long unsigned int rxId; MCP_CAN CAN0(10); // Set CS to pin 10 void setup() CAN0.init_Mask(0,0,0x06FF0000); // Init first mask... Serial.println("MCP2515 Library Mask & Filter Example..."); void loop() /********************************************************************************************************* Could you tell me if I'm wrong or if it's doesn't work yet ? |
There was a bug in the library, re-download or correct the typo in mcp_can.cpp. Also, there are five filters and two masks, by only setting one, you will receive ID 000 and potentially receive extended ID 00000000 as well. The mask should be 7FF otherwise that mask will receive IDs 612 and 712 since that bit isn't masked and thus ignored.
|
thank you !! perfect. I changed init line, giving MODE_CONFIG constant parameters, and replacing STDEXT by MODE_CONFIG in your library. I was able to set mask and filter before set normal mode, even if I have error while returning to previous mod :) It's work fine ! |
Can you post the complete modified library? Thanks mate. |
Use my fork of this CAN library... and set your masks and filters before the CAN.setMode(MCP_NORMAL) function in the setup function. If you need to change masks and filters while live, your routine will have to CAN.setMode(MCP_LOOPBACK), do changes and then CAN.setMode(MCP_NORMAL) or the filters and masks behave in undesirable ways. |
Hello,
I have got still trouble with setting Filters and Masks when other Nodes are sending messages very fast:
My Shield is using in industrial application and I do not have influence if other nodes are sending and with which frequency. So when there is a node sending messages (with IDs which should be blocked) when MCP is initializing, filtering does not work because I only can call init_Mask and init_Filt after CAN.begin is called. Maybe it is better if there is a possibility to set filters and masks before CAN.begin.
Example: A node is sending on ID 5 very, very fast all time.
When starting sketch I call CAN.begin and init_Mask and init_Filt to receive ID 522 only.
The result: No message is filtered. All messages from all IDs arrive the buffer. MCP gets overflow.
_If there is no other Node sending data when resetting MCP, the filtering is working find and only ID 522 comes into buffer._
The text was updated successfully, but these errors were encountered: