CAN with 500Kb/s

tommaier
Posts: 2
Joined: Tue Mar 22, 2022 10:31 pm

CAN with 500Kb/s

Postby tommaier » Tue Mar 22, 2022 10:54 pm

Hello,

I am using the ESP32 with a SN65HVD230 CAN transceiver. It works fine on 125Kb/s but not on higher bit rates.
The target bitrate is 500Kb/s but I get ESP_ERR_INVALID_STATE with that.
I have tried it without any connections, connected to a termination resistor and connected to the bus, same result each time.
Unfortunately I only have an analog oscilloscope and a logic analyzer for debugging hardware related issues.
Any ideas what I could be doing wrong?

Code: Select all

#include "driver/gpio.h"
#include "driver/can.h"

can_message_t message;

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

  can_general_config_t g_config = CAN_GENERAL_CONFIG_DEFAULT(GPIO_NUM_4, GPIO_NUM_5, CAN_MODE_NO_ACK);
  can_timing_config_t t_config = CAN_TIMING_CONFIG_500KBITS();
  can_filter_config_t f_config = CAN_FILTER_CONFIG_ACCEPT_ALL();

  can_driver_install(&g_config, &t_config, &f_config);
  can_start();

  message.identifier = 0x23;
  message.flags = CAN_MSG_FLAG_EXTD;
  message.data_length_code = 1;
  message.data[0] = 0x04;
}

void loop() {
  esp_err_t error = can_transmit(&message, pdMS_TO_TICKS(4300));
  if (error != ESP_OK) Serial.println(esp_err_to_name(error));
  delay(500);
}

tommaier
Posts: 2
Joined: Tue Mar 22, 2022 10:31 pm

Re: CAN with 500Kb/s

Postby tommaier » Sat Mar 26, 2022 2:00 pm

I have done some more testing with the oscilloscope;

At 125Kb/s everything works as expected.

At 250Kb/s the data that is sent by the ESP is wrong so the data on the bus is also wrong.

At 500Kb/s no data is sent by the ESP and no data is on the bus.

So it looks like the transceiver is working correctly but not the ESP32. I have also tried programming with platform.io in case the issue is caused by the Arduino IDE but the result was the same.

My code is pretty much exactly the same as the example so I don't think that should be the problem.
And since it works with 125Kb/s the CAN controller probably also works.

To me this looks like a issue in the driver/can library. Any ideas what I could try to solve this?

macinmoss
Posts: 1
Joined: Thu Sep 21, 2023 9:55 pm

Re: CAN with 500Kb/s

Postby macinmoss » Thu Sep 21, 2023 10:00 pm

I have the same issue you are seeing. I did figure it out. The knockoff can transceiver they used crashes at speeds over 125kb/s. I replaced it with a hot air tool with a microchip MCP2551 and it's working great. Hope this helps you.

Who is online

Users browsing this forum: Baidu [Spider] and 107 guests