Comments (10)
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.
from arduino_can_bus_mcp2515.
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...
from arduino_can_bus_mcp2515.
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.
from arduino_can_bus_mcp2515.
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).
from arduino_can_bus_mcp2515.
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.
from arduino_can_bus_mcp2515.
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>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
MCP_CAN CAN0(10); // Set CS to pin 10
void setup()
{
Serial.begin(115200);
if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK) Serial.print("MCP2515 Init Okay!!\r\n");
else Serial.print("MCP2515 Init Failed!!\r\n");
pinMode(A5, INPUT); /*I'm using TFT SCREEN which need pin 2, so i plugged pin 2 of canbus shield to A5 on my uno board */
CAN0.init_Mask(0,0,0x06FF0000); // Init first mask...
CAN0.init_Filt(0,0,0x06120000); // Init first filter...
Serial.println("MCP2515 Library Mask & Filter Example...");
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
}
void loop()
{
if(!digitalRead(A5)) // If pin 2 is low, read receive buffer
{
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
Serial.print("ID: ");
Serial.print(rxId, HEX);
Serial.print(" Data: ");
for(int i = 0; i<len; i++) // Print each byte of the data
{
if(rxBuf[i] < 0x10) // If data byte is less than 0x10, add a leading zero
{
Serial.print("0");
}
Serial.print(rxBuf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/ `
Could you tell me if I'm wrong or if it's doesn't work yet ?
from arduino_can_bus_mcp2515.
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.
CAN0.init_Mask(0,0,0x07FF0000); // Init mask...
CAN0.init_Mask(1,0,0x07FF0000); // Init mask...
CAN0.init_Filt(0,0,0x06120000); // Init filter...
CAN0.init_Filt(1,0,0x06120000); // Init filter...
CAN0.init_Filt(2,0,0x06120000); // Init filter...
CAN0.init_Filt(3,0,0x06120000); // Init filter...
CAN0.init_Filt(4,0,0x06120000); // Init filter...
from arduino_can_bus_mcp2515.
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 !
https://www.youtube.com/watch?v=zJZtAQl4v20
from arduino_can_bus_mcp2515.
Can you post the complete modified library?
Thanks mate.
from arduino_can_bus_mcp2515.
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.
from arduino_can_bus_mcp2515.
Related Issues (20)
- Error Sending Messages... HOT 4
- MCP_CAN on ESP8266 NodeMCU - SPI not correct? HOT 2
- ext not initialized in sendMsgBuf HOT 1
- Second Mask and Filters Not Working HOT 2
- Speed selection is incorrect. HOT 1
- Extended ID issue
- can this library be used with stm32f103c8t6?
- Required to Reinit Driver Consistently
- Is This Possible to send String data ?
- RobotDyn Shield HOT 4
- SdFat + MCP_CAN_lib
- RTR code HOT 1
- mcp_can.h no such file or directory error
- spelling error in repo name HOT 1
- Identifying Car Data MCP2515
- error compiling for ESP32 dev module HOT 2
- sharing the Arduino_CAN_BUS_MCP2515
- Drive(control) Motor With MCP2515
- Probably invalid transmission check?
- Install does not work in Windows 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino_can_bus_mcp2515.