CANbus giving unexpected messages

I am trying to integrate my Electron (OS 1.5.2) with a CANbus enabled device. I currently have a transceiver (SN65HVD230) connected to the CAN TX and RX lines of the Electron with the CANL and CANH connected to the appropriate lines of the device.

I am not receiving valid responses from the device so I hooked up a oscilloscope (shown below) and found that the Electron is sending and receiving the same hex value over and over again at a much faster rate than expected which is creating an invalid CAN message. I am fairly new to CANbus so I might be utilizing CANbus incorrectly.

Any help would be much appreciated.


The above picture is running the code below


SYSTEM_MODE(MANUAL);
SerialLogHandler logHandler;
CANChannel can(CAN_C4_C5);

void setup() {
  delay(2500);
  can.begin(50000);
}

void loop() {
  
  CANMessage message;

  message.id = 0x100;
  message.len = 1;
  message.data[0] = 42;
  can.transmit(message);

  int status = can.errorStatus();
  if(can.errorStatus() == CAN_BUS_OFF) {
    Log.info("Not properly connected to CAN bus");
  } else if (status == CAN_ERROR_PASSIVE) {
    Log.info("Passive");
  } else { 
    Log.info("Connected");
  }

  Log.info("Available: %i", can.available());
  Log.info("Enabled: %i", can.isEnabled());

  delay(1000);

}

As of now, the queue keeps getting populated with messages until it runs out of room. Below is the continuous output I am receiving.

0000060598 [app] INFO: Passive
0000060598 [app] INFO: Available: 0
0000060598 [app] INFO: Enabled: 1
0000061599 [app] INFO: Passive
0000061599 [app] INFO: Available: 0
0000061599 [app] INFO: Enabled: 1
0000062599 [app] INFO: Passive
0000062599 [app] INFO: Available: 0
0000062600 [app] INFO: Enabled: 1
0000063600 [app] INFO: Passive
0000063600 [app] INFO: Available: 0
0000063600 [app] INFO: Enabled: 1
0000064600 [app] INFO: Passive
0000064601 [app] INFO: Available: 0
0000064601 [app] INFO: Enabled: 1

Do you have 120 ohm termination resistors on both ends of the CAN bus? There should be exactly two, one at each end and none at any intermediate nodes (if any).

It looks like your transceiver on the Electron has the terminator always enabled, but you need one on the other end as well.

If you’re tapping into the middle of an existing CAN bus, you’ll need to remove the termination resistor on your transceiver. Many of them have a jumper for that, but unfortunately the one linked above does not.

1 Like