Fun and games with CAN

Thread Starter

StrongPenguin

Joined Jun 9, 2018
307
On this new ship I'm on, a lot of the gadgets are connected via CAN bus. This got me thinking about making a small CAN system on a few breadboards, just for fun and learning.

Say I want to have 5 nodes, something like this, to cover as many functions as possible:

  1. Temperature sensor (analog read input and alarm, high priority)
  2. Valve open/close (digital output)
  3. PWM for motor (control with a potentiometer)
  4. Bilge alarm (digital input, low priority)
  5. Engine alarm (digital input, high priority)

Could you guys help me with which parts to acquire? I was thinking a separate MCU for each node is necessary. And I would also like to keep things clean, so if I have to order one of each to keep things separate, I will do that gladly. If it is possible to program the MCU in a Curiosity HPC, that would be a huge plus.

This project is probably way over my skill level, but I tend to be more eager to learn and finish it, if it is ship related:)
 

John P

Joined Oct 14, 2008
2,026
Last year I bought a few of those interfaces that Yaakov showed, and connected two Arduino Nanos together with them, and had a contact closure on each board set the state of an LED on the other board. Each one sent a packet at some similar interval to the other, maybe 100 times a second, I forget. But anyway, of course the clocks weren't exactly the same frequency, so when I looked at the transmission line on a scope, the packets were clearly visible crawling toward each other, fusing for a short period and then crawling apart again. And it did seem as though when both processors were trying to transmit, the system sorted out how the data was going to get sent. But beyond setting it up and saying "Wow, that's neat" I never found an actual need to use it.
 

Irving

Joined Jan 30, 2016
3,894
These look very useful: https://www.amazon.com/HiLetgo-MCP2515-TJA1050-Receiver-Arduino/dp/B01D0WSEWU/

While I haven't used these specific boards, I have been very happy with HiLetgo products. They seem to be just a little better than other Chinese sources on these jellybean modules. Manufacturing and support are better than many. You pay a little more but it's worth it.
I've used exactly the same modules on Arduino UNO and Nano and also this bus interface module on ESP32 boards (with built-in controller) in a multi-node configuration. They all work well as long as the cable is properly twisted and you terminate correctly. Arduino are speed limited to around 125kbps depending on workload, ESP32 are easily good to 1Mbps. I've also used this module to connect to a PC for monitoring and/or the main command & control node.

What you want to do is pretty straight-forward but does need some planning. You can invent your own message types or look for suitable ones in the standard industry messages as defined in SAE:J1939 et al, or look at CANOpen messages.

Anything you need to know, just ask...
 

atferrari

Joined Jan 6, 2004
4,771
Long time ago after reading the heavy pdf on the protocol, I implemented a 3 nodes network with a PIC 18F4585 plus TI xceivers (which I got as free samples here locally, kind of a magic moment in my life).

Contrary to all the suggestions I've read to test them in a working network, once interconnected, the three nodes communicated flawlessly.

The datasheet was a little fuzzy about some registers related to the ECAN peripheral.

I recall passing the code to an EPE forum member in UK who got it up and running with no trouble.

As with so many of my projects , once I felt the hardest part was done, I lost interest.

Señor Pingüino, pure Assembly code (and maybe even a schematic) should be available.
 

John P

Joined Oct 14, 2008
2,026
... Arduino are speed limited to around 125kbps depending on workload, ESP32 are easily good to 1Mbps. ...
That's a bit misleading. Any processor can communicate via CAN at any speed, but the issue would be how rapidly messages have to be handled, and that's where "depending on workload" comes in. The Amazon listing for the the HiLetgo interface boards says "support CAN V2.0B specification, the communication speed 1Mb / S".
 

Irving

Joined Jan 30, 2016
3,894
That's a bit misleading. Any processor can communicate via CAN at any speed, but the issue would be how rapidly messages have to be handled, and that's where "depending on workload" comes in. The Amazon listing for the the HiLetgo interface boards says "support CAN V2.0B specification, the communication speed 1Mb / S".
You are indeed correct, its all about throughput. Having said that, I did have problems with the SPI clock rate on the Arduino @10MHz and could ony get reliable communications with a clock rate <4MHz.
 
Top