Is this possible?: CAN Transceiver Loopback test

Hi Everyone,

I had a sketch that is sniffing for CAN devices (I have a brushless motor controller over CAN) and it didn't work.

Components:

  • Teensy 4.1
  • Sn65Hvd230 Bus Transceiver

So I tried to do a loopback test and that didn't work either.

My loopback is just connecting CANH and CANL - I only saw one other post testing this board but it used 2 transceivers.

ChatGPT tells me a loopback with 1 transceiver should work. Is that wrong?

And is the easiest way to test if CAN is working, by using 2 of these modules?

Here is a diagram

And here is the code.

On the serial monitor it shows the message sending but nothing recieved,

#include <FlexCAN_T4.h>

FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
CAN_message_t msgTx, msgRx;
elapsedMillis sendTimer;

void setup() {
  Serial.begin(115200);
  delay(500);

  Serial.println("FlexCAN_T4 minimal test");

  Can1.begin();
  Can1.setBaudRate(500000);  // Match transceiver speed

  msgTx.id = 0x123;
  msgTx.len = 8;
  for (int i = 0; i < 8; i++) {
    msgTx.buf[i] = i + 1;
  }
}

void loop() {
  if (sendTimer > 1000) {
    Serial.println("Sending CAN message...");
    Can1.write(msgTx);
    sendTimer = 0;
  }

  if (Can1.read(msgRx)) {
    Serial.print("Received ID: 0x");
    Serial.println(msgRx.id, HEX);
    Serial.print("Data: ");
    for (int i = 0; i < msgRx.len; i++) {
      Serial.print(msgRx.buf[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
  }
}

Yes I tried swapping RX and TX too.

If this is impossible I'll try with 2 transceivers. Thanks for any replies!

Thanks

Yes. That is not correct. CAN bus requires a second device to ACK each frame. Without that transmission fails.

That, and CAN bus is a bus. There is no such thing as a transmit line nor a receive line. Signaling is by creating a differential between the two lines. It is not serial communications.

1 Like

Okay! That clarifies :slight_smile:

Thank you!

In that case - I'm considering just trying to detect a connected motor controller.

If you have time, could you also let me know: would a packet sniffer work for a connected CAN device, or does that device (a motor) need to be doing something to be detectable?

Maybe. A receiver can be put in a passive mode. In that mode it does not ACK. If the sniffer ACKs, you're good. If not, you're not.

I have a vague recollection that some CAN bus controllers / transceivers can "self receive". You may be able to do that to get loopback working.

to test Canbus systems I find it useful to have a USB-CANBUS dongle, e.g. LAWICEL CANUSB
this enables a PC to test canbus interfaces and monitor data flows