Code Monkey home page Code Monkey logo

Comments (2)

coryjfowler avatar coryjfowler commented on May 30, 2024

Set both masks to 0x7FF and all the filters to 0x20A (522 in hex). That should guarantee only 522 is the only ID received.

num is the filter (0 to 5) or mask (0 to 1) to set.
ext tells the library if we are using extended (1) or standard (0) IDs.
ulData is the number to set.

from arduino_can_bus_mcp2515.

if2s avatar if2s commented on May 30, 2024

Thank you. It is working this way but there are some problems with error checking and filtering messages after reset.

I use CAN.checkError() before every reading so that I know if there are some lost frames. The result after an error is permanently CAN_CTRLERROR (5) because datasheet says, eflg has to be reset manually. Maybe it will be a good idea to implement this in library (something like reset_error(void)).

The other problem: 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.

    if(CAN_OK == CAN.begin(CAN_500KBPS))                   // init can bus : baudrate = 500k
    {
        Serial.println("CAN BUS Shield init ok!");
        CAN.init_Mask(0, 0, 0x3FF);
        CAN.init_Mask(1, 0, 0x3FF);
        CAN.init_Filt(0, 0, 0x20A);
        CAN.init_Filt(1, 0, 0x20A);
        CAN.init_Filt(2, 0, 0x20A);
        CAN.init_Filt(3, 0, 0x20A);
        CAN.init_Filt(4, 0, 0x20A);
        CAN.init_Filt(5, 0, 0x20A);
        delay(100);
        Serial.println("masks and filters set!");
    }

The result: No message is filtered. All messages from all IDs arrive the buffer.

If there is no other Node sending data when resetting MCP, the filtering is working find and only ID 522 comes into buffer.

from arduino_can_bus_mcp2515.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.