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);
}