ESP32 + built-in CanBus -> not working

Hello everyone,

I can use CanBus using MCP2515 driver.

But I'm trying to use the internal driver of ESP32. The electronic is more simple and not use crystal.

I'm using :

  • ESP32 (board NodeMCU-32S)

  • mini board with TJA1050

image

but it not working, and I'm not understand why the reason.
The messages on terminal stop with "Sending packet ..."

I try to debug and I found that the code stops on "yield ()", on function : "endPacket ()", on ESP32SJA1000.cpp:

  // wait for TX complete
  while ((readRegister(REG_SR) & 0x08) != 0x08) {
    if (readRegister(REG_ECC) == 0xd9) {
      modifyRegister(REG_CMR, 0x1f, 0x02); // error, abort
      return 0;
    }
    yield();
  }

I try change the ESP32, mini board with TJA1050, try to solder the pins but its continue not working ...

Does anyone have an idea why it doesn't work?

Thank you.
Jorge Torres

I have the following circuit to try understand why the CanBus not work :

in both ESP32 I programmed the following code :

// Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#include <CAN.h>

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

  Serial.println("CAN Sender");

  // start the CAN bus at 500 kbps
  if (!CAN.begin(500E3)) {
    Serial.println("Starting CAN failed!");
    while (1);
  }
}

void loop() {
  // send packet: id is 11 bits, packet can contain up to 8 bytes of data
  Serial.print("Sending packet ... ");

  CAN.beginPacket(0x12);
  CAN.write('h');
  CAN.write('e');
  CAN.write('l');
  CAN.write('l');
  CAN.write('o');
  CAN.endPacket();

  Serial.println("done");

  delay(1000);

  // send extended packet: id is 29 bits, packet can contain up to 8 bytes of data
  Serial.print("Sending extended packet ... ");

  CAN.beginExtendedPacket(0xabcdef);
  CAN.write('w');
  CAN.write('o');
  CAN.write('r');
  CAN.write('l');
  CAN.write('d');
  CAN.endPacket();

  Serial.println("done");

  delay(1000);
}

and ESP32 stops showing in the terminal :
image

Your schematic does not show termination resisters on each end of the bus. There should be two 120 ohm resistors, one on each physical end of the bus. The receiver must be active when sending a message as it must be acknowledged by another node on the bus.

I checked and both have 120 ohm resistor :

I measured, with CANH/CANL disconected this have 120 ohm, and connected have 60 ohm

with logical analyser I have (TX1, RX1 , TX2, RX2) :

Any aditional electronics are needed ? pull-up resistors on TX or RX ?

From the picture that does not compute. The can driver/transceiver modules are not connected to the ESP unless you have done so on the back of the board which I am assuming you have done. They are connected to each other correctly. These transceiver modules only translate signals to and from the micro to the bus. All of the logic is in the controller (ESP device). I like at least 1 meter distance or more, I have had problems with very short buss lines.

The I MCP2515 is not a driver but a controller. I do not know if the ESP uses a similar construction internally. The TJA1050 is the CAN bus driver. You have them connected properly per your drawing. I assume you are using the Espressif ESP32 wiring diagram and software examples.

The other thing is I start very slow so I can see the bits on my scope and look for the ACK bit. If that is there the remote is responding and the message is close if not correct. There are some cheap (under $10 US) available on the web and they work ok. They are nice for this type of thing and they will decode different protocols. Hopefully this helps. I am not familiar with the library you are using, hopefully some of the others here can help with that.

Yes, I connected on the back with wires and solded them.
I tried with 2 m of cable, but the problem persist.

Have you looked at the data sheet? If it is a TJA1050 it probably will not work, that is a 5V part. You could use something like a LTC2875 as it is 3 and 5V compatible. Before you change try using a diode in series with the 5V power supply to the transceiver module. If it gets better we are on the right track. There are also mods on the internet showing how to modify the transceiver module for 3.3V/5V. I use 5V systems so I am sorry I missed this one.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.