1
\$\begingroup\$

I have a Linux Ubuntu based Machine and a esp32 which both contain a CAN interface. I am also using two CJMCU-230 transreciver. The Problem is that everytime when I connect the rx and tx of the Linux machine to the transreciver, while the esp32 and the other transreciver is connected, CANL stays LOW and CANH stays HIGH as if they froze. When doing the same thing with two esp32 everything works fine. I checked the wiring and am 99% sure that there is no short, I am using termination resistors at both ends of the bus with 120 ohm, I made sure that the transreciver are working and when switching the Linux machine to loopback mode it seems to be fine so I don't think that it is faulty.

My wiring is as follows: (all grounds are connected)

esp32 to transreciver:

  • 3.3v -> 3.3 ->3.3 (esp powers both transrecivers)
  • GND -> GND
  • TX2 -> CTX
  • RX2 -> CRX

transreciver to transreciver:

  • CANL -> CANL
  • CANH -> CANH
  • GND -> GND

linux to transreciver:

  • RX -> CRX
  • TX -> CTX
  • GND -> GND

As I said before the weird thing is that when connecting another esp32 instead of the Linux machine than it works fine.

To configure the CAN interface I use following commands:

  • ip link set can0 type can bitrate 250000
  • ip link set can0 up

To send data I use:

  • cangen can0 -g 1000

The code to that is running on the esp32 is used to reciver any message from the CAN bus:

#include <Arduino.h>
#include <CAN.h>

//FOR ESP32
#define TX_GPIO_NUM   17  // Connects to CTX
#define RX_GPIO_NUM   16  // Connects to CRX

void canReceiver() 
{
  //get size of a packet if one exists
  int packetSize = CAN.parsePacket();

  if (packetSize)
  {
    //received a packet
    Serial.print("Received ");

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

    if (CAN.packetRtr()) 
    {
      //Remote transmission request 
      //packet contains no data
      Serial.print ("RTR ");
    }

    Serial.print ("packet with id 0x");
    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);

      // only print packet data for non-RTR packets
      while (CAN.available()) 
      {
        Serial.print ((char) CAN.read());
      }
      Serial.println();
    }

    Serial.println();
  }

}

void setup() {
  Serial.begin(115200);
  while (!Serial);

  Serial.println ("CAN Receiver/Receiver");

  // Set the pins
  CAN.setPins (RX_GPIO_NUM, TX_GPIO_NUM);

  // start the CAN bus at 250 kbps
  if (!CAN.begin (250E3)) {
    Serial.println ("Starting CAN failed!");
    while (true);
  }
  else {
    Serial.println ("CAN Initialized");
  }
}

void loop() 
{
  canReceiver();
}

When I start sending frames from the Linux machine the CANL and CANH are inverted and produce error frames which cause the tx error to go up. I really do not know what to do anymore so if anyone could help I would really appreciate it :)

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

when I connect the rx and tx of the Linux machine to the transceiver ... CANL stays LOW and CANH stays HIGH

when I start sending frames from the Linux machine the the Linux machine the CANL and CANH are inverted

switching the Linux machine to loopback mode it seems to be fine

It sounds as though the linux machine uses inverted logic levels on its CAN Tx and Rx pins. Most CAN transceiver chips use logic levels on the Tx and Rx signals as logic LOW as CAN dominant, logic HIGH as CAN idle.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.