I use the twai and can successfully write and receive frames. However, when I reset the esp23 I see error frames showing up. It seems that the esp_tx pin sends a negative pulse on initialization which results in an error on the bus. How can I prevent this? You can see what happens in the screenshots I added.
This is the code I use to initialize the twai.
// Initialize configuration structures using macro initializers
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT( CAN_TX,CAN_RX, TWAI_MODE_NORMAL);
g_config.tx_queue_len = 10;
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_100KBITS();
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
// Install TWAI driver
// negative pulse occures in next function
if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
printf("Driver installed\n");
} else {
printf("Failed to install driver\n");
return;
}
// Start TWAI driver
if (twai_start() == ESP_OK) {
printf("Driver started\n");
} else {
printf("Failed to start driver\n");
return;
}
Board: ESP32-S3-DevKitC-1 v1.0
ESP-IDF: platform-espressif32 6.4.0
CAN transceiver: SN65HVD232DR
esp_twai_tx_pin: GPIO_NUM_11
esp_twai_rx_pin: GPIO_NUM_12
Logic anayzer GPIO
savy can error messages
I tried to assign the TX pin as output before initialization, but it did not help as the pin is reinitialized in the driver initialization
// Set CAN_RX pin as output and high
gpio_set_direction(CAN_TX, GPIO_MODE_OUTPUT);
gpio_set_level(CAN_TX, 1);
// glitch is here
// negative pulse occures in next function
if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
printf("Driver installed\n");
} else {
printf("Failed to install driver\n");
return;
}