CAN bus transport implementation
-
Are You still have an issue when
MY_DEBUGis deactivated? Have You tried to add delay as is was suggested in one of the threads You found? -
@Adam-Slowik, @JeeLet
Ok, I will give CAN-Bus a try. This is my test setup:
I will use the demo sketches from Adam's fork. Let you know how it works for me.
-
"Are my ideas good" .. yes yes c'est tout bon
"It will not flash the diodes in case of communication problems" ... it's not a problem, Christmas is still far :)
But yes a counter that increments is a good thing.
what do you want me to test ????
bool transportSanityCheck(void) { return (CAN0.getError()==CAN_OK) }The "radio guy" opinion would be great.
((I'll look for possible help ). )Re-Edit
hal/transport/CAN/MyTransportCAN.cpp
bool transportSanityCheck(void) { // not implemented yet return true; }:stuck_out_tongue_winking_eye:
Edit
I searched the web, and using SNR RSSI with the CAN bus is a dead end.
https://www.thethingsnetwork.org/docs/lorawan/rssi-and-snr/what do you want me to test ????
bool transportSanityCheck(void) { return (CAN0.getError()==CAN_OK) }The "radio guy" opinion would be great.
((I'll look for possible help ). )I'm not a "radio guy", but I think this code change looks fine. When sanity check fails then MySensors core calls transportInit() which would try to re-initialise the MCP2515 module.
In my setup with only 2 CAN modules I'm afraid this will always return CAN_OK. So no idea how to check this. May be unplug the both CAN wires?
-
@Adam-Slowik, @JeeLet Ok, with the both sketches it works with some limitations.
Nice work so far - thank you for contributing!I have done some modifications in the CAN transport files.
@Adam-Slowik I would like to create a PR in your forked repo. Then we can discuss the code changes in GitHub. Would that be Ok for you - do you have time for this?One limitation I found so far are long MyMessages. They can be up to 32 byte - which results in up to 4 CAN-Bus sub telegrams. When I send 32 byte message I observed the sub telegrams do not always arrive in send order in MyTransportCAN.cpp like this:
19916 CAN:RCV:CANH=2202010368,ID=3,TOTAL=4,CURR=0,TO=3,FROM=0 19921 CAN:RCV:LN=8,DTA0=0,DTA1=0,DTA2=3,DTA3=202,DTA4=9,DTA5=2,DTA6=0,DTA7=49 19929 CAN:RCV:SLOT=0,PART=1 19932 CAN:RCV:CANH=2202075904,ID=3,TOTAL=4,CURR=1,TO=3,FROM=0 19937 CAN:RCV:LN=8,DTA0=50,DTA1=51,DTA2=52,DTA3=53,DTA4=54,DTA5=55,DTA6=56,DTA7=57 19945 CAN:RCV:SLOT=0,PART=2 19947 CAN:RCV:CANH=2202206976,ID=3,TOTAL=4,CURR=3,TO=3,FROM=0 19953 CAN:RCV:LN=8,DTA0=56,DTA1=57,DTA2=48,DTA3=49,DTA4=50,DTA5=51,DTA6=52,DTA7=53 19960 !CAN:RCV:proper slot not found 19964 CAN:RCV:CANH=2202141440,ID=3,TOTAL=4,CURR=2,TO=3,FROM=0 19970 CAN:RCV:LN=8,DTA0=48,DTA1=49,DTA2=50,DTA3=51,DTA4=52,DTA5=53,DTA6=54,DTA7=55 19978 CAN:RCV:SLOT=0,PART=3Sub telegram 3 arrives before 2.
I'm afraid the function _findCanPacketSlot() needs an update to handle this.
@Adam-Slowik Do you see a chance for you to update the logic next time?Other limitation I see is the limited CAN telegram buffer of 3 packets in the MCP2515 module. I'm afraid for reliable operation with MySensors a change from polling to interrupt mode is required.
But this can be done later, after the fix for the PacketSlot logic. -
In logic analyser it looks like this:

Upper 4 channels are from node, lower ones are from gateway.Close up from gateway send (4 packets):

-
@virtualmkr said in CAN bus transport implementation:
I'm not a "radio guy", but I think this code change looks fine. When sanity check fails then MySensors core calls transportInit() which would try to re-initialise the MCP2515 module.
Ok. I'll update code.
@virtualmkr said in CAN bus transport implementation:
I have done some modifications in the CAN transport files.
@Adam-Slowik I would like to create a PR in your forked repo. Then we can discuss the code changes in GitHub. Would that be Ok for you - do you have time for this?Sure. Make PR. I'll try to review it within 48h.
@virtualmkr said in CAN bus transport implementation:
When I send 32 byte message I observed the sub telegrams do not always arrive in send order
Other limitation I see is the limited CAN telegram buffer of 3 packets in the MCP2515 module. I'm afraid for reliable operation with MySensors a change from polling to interrupt mode is required.
I think this two issues are linked. Now packets are sent in correct order (could You verify it?). If packets are sent in short periods We should use interrupt to keep MCP2515 buffers empty. When We fail to keep buffers empty (due to polling mechanism) We receive sub telegrams in mixed order. This theory could be true if MCP2515 buffers are implemented as LIFO. I'll look into documentation to figure it out.
Anyway both fixes are worth to implement. I'll try to do this over weekend. -
Hello
CAN Bus is still functional, and no problem.a question : is it possible to implement the use of 2 CAN Module on the same Gateway.
2 CAN bus or RS485 + CANas for the RS485 in example for a Mega2560 board
MyConfig.h ...... * Example: @code #define MY_RS485_HWSERIAL Serial1 @endcode */ //#define MY_RS485_HWSERIAL (Serial1)