Sending SWCan Messages

I am looking at the examples around for sending messages on the SW bus and have become confused.
The sketch SW_CAN_START.INO located at https://gist.github.com/macchina/ac0db2bc45774836d6fe2a5758b12e06 has a library that is not available: #include <mcp_can.h>. Appears to me that the library has been renamed and some functions changed so that the sketch no longer compiles. In addition it is stated that “It is recommended you use macchina/Single-Wire-CAN-mcp2515 instead of this library.”

  1. Is it possible for someone to rewrite the Sketch SW_CAN_START.INO using the Single-Wire-CAN-mcp2515 library?
  2. Any Hints on the message IDs to look for the wake and initalize messages?

Thanks,
Colin

Hi other Colin. :wink:

  1. Yes, you need the mcp2515 library instead: https://github.com/macchina/mcp2515 It does have examples. I’ve further developed that library but it isn’t official. You need my version only if you’re trying to compile M2RET or something like that.

  2. On single wire CAN the wakeup message 0x100. It doesn’t need any data bytes. 0x100 is sent with high voltage wake up (so it is sent with 12v signalling instead of about 3v). You might see polling messages that start with 0x13FF??? those should be messages from each node on the bus saying they’re still around.

Hey Collin,
Thanks for the reply. lol
Looking at the examples it is not clear how the High Voltage Wakeup, Normal Mode and Sleep mode are set on the SW bus. Are there functions in the library that handle this or do I just set mode pins within my sketch?
Thanks,
Colin

There’s another library for that: https://github.com/macchina/Single-Wire-CAN-mcp2515

Or you can just toggle the pins yourself if you want.

At this point is there any reason you wouldn’t want to submit your changes as a pull request to Macchina? Your library has been in-use with M2RET for a few months now so it presumably stable.

Well, just haven’t done it yet I suppose. The biggest reason I haven’t pushed my changes is that I changed A LOT. The new MCP2515 library has a dependency on can_common which is a common interface between MCP2515, due_can, and now some other CAN libraries. The idea is that you can load whichever driver necessary for your board and use the exact same function calls on any of them. Using the MCP2515 and due_can would be exactly the same. It also allows for doing things like creating a function that takes a reference to a CAN object. You could, for instance, create a function that sends things out the CAN bus and it can take a pointer to either a due_can or MCP2515 derived object. They both inherit from can_common now and so you can take a pointer of type CAN_COMMON and use the exact same methods whether it is due_can, mcp2515, or one of the other up and coming libraries for other hardware. That’s powerful but it means I changed a lot and it might break people’s sketches. So, I’ve been hesitant to change over the Macchina repo just yet. But, it probably should eventually happen.