RX doesnt work with TWAI libary

uitsteller1
Posts: 1
Joined: Thu Dec 09, 2021 12:56 pm

RX doesnt work with TWAI libary

Postby uitsteller1 » Thu Dec 09, 2021 2:40 pm

Hi,

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.
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "esp_err.h"
  6. #include "esp_log.h"
  7. #include "driver/gpio.h"
  8. #include "driver/twai.h"
  9. #include "esp_rom_gpio.h"
  10. #include "esp_rom_sys.h"
  11.  
  12. /* --------------------- Definitions and static variables ------------------ */
  13. //Example Configuration
  14. #define TX_GPIO_NUM                     5
  15. #define RX_GPIO_NUM                     4
  16.  
  17.  
  18. static void can_setup(void)
  19. {
  20.     //Initialize configuration structures using macro initializers
  21.     twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(TX_GPIO_NUM, RX_GPIO_NUM, TWAI_MODE_NORMAL);
  22.     twai_timing_config_t t_config = TWAI_TIMING_CONFIG_25KBITS();
  23.     twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
  24.  
  25.     //Install TWAI driver
  26.     if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
  27.         printf("Driver installed\n");
  28.     } else {
  29.         printf("Failed to install driver\n");
  30.         return;
  31.     }
  32.  
  33.     //Start TWAI driver
  34.     if (twai_start() == ESP_OK) {
  35.         printf("Driver started\n");
  36.     } else {
  37.         printf("Failed to start driver\n");
  38.         return;
  39.     }
  40.  
  41. }
  42.  
  43. void app_main(void)
  44. {
  45.     can_setup();
  46.    
  47.     while(1)
  48.     {
  49.         //Configure message to transmit
  50.         twai_message_t message;
  51.         message.identifier = 0xAAAA;
  52.         message.extd = 1;
  53.         message.data_length_code = 4;
  54.         for (int i = 0; i < 4; i++) {
  55.             message.data[i] = 0;
  56.         }
  57.  
  58.         //Queue message for transmission
  59.         if (twai_transmit(&message, pdMS_TO_TICKS(1000)) == ESP_OK) {
  60.             printf("Message queued for transmission\n");
  61.         } else {
  62.             printf("Failed to queue message for transmission\n");
  63.         }
  64.         vTaskDelay(1000 / portTICK_RATE_MS);
  65.     }
  66. }
ouput
  1. Driver installed
  2. Driver started
  3. Message queued for transmission
  4. Message queued for transmission
  5. Message queued for transmission
  6. Message queued for transmission
  7. Message queued for transmission
  8. Message queued for transmission
  9. Message queued for transmission
  10. Message queued for transmission
  11. Message queued for transmission
  12. Message queued for transmission
  13. Message queued for transmission
  14. Message queued for transmission
  15. Message queued for transmission
  16. Message queued for transmission
  17. Message queued for transmission
  18. Message queued for transmission
  19. Failed to queue message for transmission
  20. Failed to queue message for transmission
  21. Failed to queue message for transmission
  22. Failed to queue message for transmission
after this there is a endless loop of failed messages

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?

reypowerlu
Posts: 3
Joined: Wed Feb 23, 2022 8:05 am

Re: RX doesnt work with TWAI libary

Postby reypowerlu » Wed Feb 23, 2022 8:33 am

I have also encountered this problem. I have checked it for a long time and think it is the official CAN function that is not supported.

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: RX doesnt work with TWAI libary

Postby ESP_Dazz » Wed Feb 23, 2022 12:05 pm

Might be something wrong with the driver's GPIO configuration. Have you tried using another set of GPIOs?

Who is online

Users browsing this forum: Google [Bot] and 80 guests