Troubleshooting CAN Bus to Control Motor

I having problems with a Arduino Uno R3 using a CAN Bus to control a RMD 4005-L-25T motor. I am not sure what my problem is, so if someone could review what I have done it might help. If you need more info on anything, feel free to ask. The motor has six pins on it:

[ CANL, CANH, GND, GND, VCC, VCC ]

I have supplied the ground pins with ground, and the power pins with 12 volts which is listed on the specification sheet. I chose the MCP2515 CAN Bus module for Arduino to communicate with the motor. I followed this guide to connect the motor to my Arduino board. This is what the labels look like:

If you look at the first image, there is a jumper on J1 (bottom right) because this is my first node in the CAN network. Now this is how everything looked connected on the breadboard:

The last thing to do was to write the code and upload it to my Arduino board. I chose the CAN fork of Adafruit's driver by Sandeep Mistry. The motor has a specification sheet for the CAN communication protocol it uses, so I followed the specification for requesting the motor's system runtime.

#include <MCP2515.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial);

  Serial.println("CAN Communication");


  if (!CAN.begin(1000E3)){
    Serial.println("Starting CAN failed.");
    while (1);
  }

  CAN.onReceive(onReceive);  //callback to defined onReceive function below
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Sending packet...");

  CAN.beginPacket(0x12);
  CAN.write(0xB1);
  CAN.write(0x00);
  CAN.write(0x00);
  CAN.write(0x00);
  CAN.write(0x00);
  CAN.write(0x00);
  CAN.write(0x00);
  CAN.write(0x00);

  CAN.endPacket();

  Serial.println("Packet send.");

  delay(1000);

}

void onReceive(int packetSize){

  Serial.println("Received packet");

  if (CAN.packetExtended()){
    Serial.print("Extended packet ");
  }

  if (CAN.packetRtr()){
    Serial.print("RTR ");
  }


  Serial.print("Packet with ID ");
  Serial.print(CAN.packetId(), HEX);

  if (CAN.packetRtr()){
    Serial.print(" and requested length ");
    Serial.println(CAN.packetDlc());
  }else{

    Serial.print(" and length ");
    Serial.println(packetSize);

    while (CAN.available()){
      Serial.print((char)CAN.read());
    }
    Serial.println();
  }

}

I power my Arduino on and provide the motor 12V and ground which gives it a green light. Then I run my code and the if statement triggers in setup for CAN failing to startup. I have tried a few other drivers for the MCP2515 CAN module, which also end up in an error.

If anyone has any ideas for how I could trouble shoot this, I would appreciate the help.

The examples for that library don't use this include.
#include <MCP2515.h>
They use this
#include <CAN.h>

Please post schematics.

1 Like

Fixed that, it made no difference though. Their CAN header only decides on what architecture to include:

#ifndef CAN_H
#define CAN_H

#if defined(ADAFRUIT_FEATHER_M4_CAN)
#include "CANSAME5x.h"
#elif defined(ARDUINO_ARCH_ESP32)
#include "ESP32SJA1000.h"
#else
#include "MCP2515.h"
#endif

#endif

I have never actually made a schematic. What software is used for it?

Use hardware, pen and paper! Set out all pin designations, voltages, amp capacity etc.

I and many others use KiCad, it is very good and will take through the gerbers needed to make a circuit board. It is free although they do ask for a donation. This program is not a one night learn it program.

Here is my amazing schematic. It might look better than the actual circuit :sweat_smile::

I honestly have not learned about some things like amp capacity yet. This diagram may be a good way for you to get an idea of my current level of knowledge.

Thanks for the recommendation. Doing it on paper was a good idea idea instead of having to rush through learn an entirely new piece of software in the moment.

Not critical this time. You power the UNO by USB and that spells: 0.5 Amp. That ought to be good enough.

Thanks for the schematics! I see no obvious mistake there.

I'm a bit rusty regarding powering CAN bus drivers.... One side is 5 volt and the other side is 12 volt. It might be okey. More details knowing people might add knowledge here.

This is good information. The circuitry is not happy.

Can something be wrong here? It's beyond my capacity to give suggestions.

Can something be wrong here?

The specification sheet states the communication frequency (I think this means bit rate) and baud rate for the motor:

Baud Rate: 9600, 19200, 57600, 115200 (default)
Communication Frequency: CAN BUS @ 1MBPS: 2kHz

The begin(bitrate) function takes in the bit rate, so I think everything matches up OK there. What confuses me is this:

You are supposed to terminate the first and last nodes with a 120 ohm resistor. On the MCP2515 module, you can just attach a jumper to J1 to terminate it, but I am not sure how to do that with the motor because the bus terminates inside. Would something like this work:

It is a little difficult to see because I had little room; but after the current returns from the motor, you put a resistor to connect the two vertical columns of CANH and CANL.

It's difficult so see what You want to show.

A harmless test, try, could be to remove the 120 Ohm at the motor side.

That makes no sense to me. The poverty of words....

HI, @usernaem86
Welcome to the forum.

With all power disconnected/turned OFF from your project, can you please measure the resistance between CANH and CANL?
This measurement will tell us if the 120R resistors are fitted.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like

You are doing a great job, nice progress. @TomGeorge tht 120 Ohm works out to be 60 Ohm for the buss as the two 120 Ohm resistors are in parallel. You might be able to simply measure the motors CAN terminals, it should up to be 120 Ohm.

Powering devices such as CAN modules with there recommended voltages is just fine. The driver chip takes care of the voltage. It is a differential bus, the voltages do not matter whiten reason.