Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Adam Slowik
    3. Best
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by Adam Slowik

    • CAN bus transport implementation

      Hi,

      I'm trying to add CAN transmission to MySensors.

      This is my fork: https://github.com/AdamSlowik/MySensors/tree/feature/can

      This is how I connected my CAN modules to arduino (except pin INT of CAN module is connected to pin 2 of arduino):
      https://www.14core.com/wiring-the-two-mcp2515-stand-alone-can-controller-with-spi/

      My CAN module is popular one (mpc2515 with tja1050)

      My fork contains following examples:
      -GatewaySerialCAN
      -CANSwitch (simpler version of BinarySwitchSleepSensor)

      Heavy lifting (MCP2515 driver stuff) is done by https://github.com/coryjfowler/MCP_CAN_lib

      After uploading mentioned sketches to arduinos, sensor sends frame. I belive this is request for new node ID (it's 7 bytes long).
      Gateway recives this frame (data is same as in sensor side). After that strange things happens. Gateway ends up in some endless loop calling 'transportDataAvailable'. This might be normal but 'IF' statement 'if(!hwDigitalRead(CAN0_INT))' is always true. Because this statement is true program reads data from CAN. Since 'IF' statement (in my opinion) is false positiv, data from CAN are garbage (0xFFFFFFFF).

      Two easiest explenation for me are:
      a) Gateway uses pin 2 and this interfere with communication code
      b) Used CAN library is somehow incompatible with MySensors

      I belive wiring issue is not the case. All things are soldered in universal board and tested with examples provided by CAN library.

      Can someone look at My code especialy at how I use pin 2?
      Perhaps someone have CAN modules to reproduce My issue?

      posted in Development
      Adam Slowik
      Adam Slowik
    • RE: CAN bus transport implementation

      Hi @JeeLet, to test my implementation You should:

      1. Set up hardware as described in my first post in this thrread.
      2. Download source from my fork (https://github.com/AdamSlowik/MySensors/archive/refs/heads/development.zip)
      3. Somewhere in Your lib folder swap official MySensors files with those downloaded.
      4. Upload "CANSwitch.ino" to first arduino and "GatewaySerialCAN.ino" to second one. Both files can be found in examples.

      If everything is fine then You Should get results similar to those presented in my post dated to "14 Jul 2020, 20:42"

      Please let Us know if You managed to reproduce My results.

      posted in Development
      Adam Slowik
      Adam Slowik
    • RE: CAN bus transport implementation

      I found a bug in my code. Please re-download new version.

      If something won't work please enable CAN debug by adding:
      #define MY_DEBUG_VERBOSE_CAN

      add this to gateway and to node sketch

      posted in Development
      Adam Slowik
      Adam Slowik
    • RE: CAN bus transport implementation

      I'm not sure if We understood each other. This line #define CAN_CLOCK MCP_16MHZ should be in Your sketch. You should not modify MyConfig.h.
      Libraries (in general not only MySensors) should not be modified. MyConfig.h is part of library.

      Let's take a look at this code from MyConfig.h

      #ifndef CAN_CLOCK
      #define CAN_CLOCK MCP_8MHZ
      #endif. 
      

      This is if statement. If user didn't defined CAN_CLOCK define it as CAN_CLOCK MCP_8MHZ
      If user defined (in sketch) CAN_CLOCK then do nothing.

      So You can treat MyConfig.h as a set of defaults which can be overridden from sketch.

      I have put all relevant (in My opinion) properties from MCP_CAN_lib into MyConfig.h, so You can override them. If I have missed some relevant property please let Me know.

      posted in Development
      Adam Slowik
      Adam Slowik