- Driver installed
- Driver started
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Message queued for transmission
- Failed to queue message for transmission
- Failed to queue message for transmission
- Failed to queue message for transmission
- Failed to queue message for transmission
I am for a pretty long time stuck with trying to get a can driver working. So first some basic information of my setup.
Hardware: ESP32-Wroom
API: ESP-IDF 4.3
Platform: VScode with PlatformIO (also used the espressif plugin, but same problem)
So i used the most simple example code to send somthing to the can driver. I used the TWAI example stated on the site. I only made it so that it send a message every second.
- #include <stdio.h>
- #include <stdlib.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_err.h"
- #include "esp_log.h"
- #include "driver/gpio.h"
- #include "driver/twai.h"
- #include "esp_rom_gpio.h"
- #include "esp_rom_sys.h"
- /* --------------------- Definitions and static variables ------------------ */
- //Example Configuration
- #define TX_GPIO_NUM 5
- #define RX_GPIO_NUM 4
- static void can_setup(void)
- {
- //Initialize configuration structures using macro initializers
- twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL);
- twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS();
- twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
- //Install TWAI driver
- 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;
- }
- }
- void app_main(void)
- {
- can_setup();
- while(1)
- {
- //Configure message to transmit
- twai_message_t message;
- message.identifier = 0xAAAA;
- message.extd = 1;
- message.data_length_code = 4;
- for (int i = 0; i < 4; i++) {
- message.data[i] = 0;
- }
- //Queue message for transmission
- if (twai_transmit(&message, pdMS_TO_TICKS(1000)) == ESP_OK) {
- printf("Message queued for transmission\n");
- } else {
- printf("Failed to queue message for transmission\n");
- }
- vTaskDelay(1000 / portTICK_RATE_MS);
- }
- }
Problem
First i checked if any message is after the can driver side, but any message is to be found. So used a logic analyzer to see if there happens something on the pin itself. I discovered that only a small pulse of 40 μs is send on the TX pin but that's it. but anything like a normal message. As you can see it fails to send a message after a few are completed. There are also no pulses detected anymore.
Already checked the logic analyzer, but it works fine. so i dont have any idea anymore where the problem lies. any suggestions?