ESP32-S2 TWAI not receiving, but sending working fine, ESP32 same code works fine

noebl1
Posts: 6
Joined: Sun Aug 08, 2021 2:53 pm

ESP32-S2 TWAI not receiving, but sending working fine, ESP32 same code works fine

Postby noebl1 » Sun Aug 15, 2021 6:56 pm

Been trying to get an ESP32-S2-Saola working with TWAI using the examples from here; https://docs.espressif.com/projects/esp ... /twai.html and https://github.com/espressif/arduino-esp32/issues/3921 . I can take the same exactly code, plug in an ESP32 board, change the GPIO and it works fine. As mentioned in the subject of the post, I can send to the other nodes fine from the ESP32-S2-Saola.

I'm not seeing any errors on the bus checking the status, the receive message queue never gets above 0 when using the ESP32-S2-Saola and not doing any filtering (again same code.) I am pretty confident the GPIO pins are talking correctly (have tried a few) through the SN65HVD230 as with it's not properly configured (like tx/rx reversed or baud rate off), the sending side sees an error as I'd expect. Not sure if I am missing something in the init, or there may be a bug. Thanks!

Code: Select all

void TWAI_setup(void)
{
  //Initialize configuration structures using macro initializers (changed GPIO type in esp idf library)
  // ESP32 twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_33, GPIO_NUM_35, TWAI_MODE_NORMAL);
  twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_5, GPIO_NUM_6, TWAI_MODE_NORMAL);
  twai_timing_config_t t_config = TWAI_TIMING_CONFIG_50KBITS();
  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("TWAI  Driver installed\n");
  else
  {
    printf("TWAI Failed to install driver\n");
    return;
  }

  //Start TWAI driver
  if (twai_start() == ESP_OK)
    printf("TWAI Driver started\n");
  else
  {
    printf("TWAI Failed to start driver\n");
    return;
  }
}


void TWAI_receive(void)
{
  twai_status_info_t twai_status;
  twai_message_t message;

  //Check for received messages
  twai_get_status_info(&twai_status);
  Serial.printf("TWAI Status: %i\n", twai_status.state);
  Serial.printf("TWAI Messages to Receive: %i\n", twai_status.msgs_to_rx);
  Serial.printf("TWAI Messages to Send: %i\n", twai_status.msgs_to_tx);
  Serial.printf("TWAI Messages Receive Errors: %i\n", twai_status.rx_error_counter);
  Serial.printf("TWAI Messages Receive Missed: %i\n", twai_status.rx_missed_count);
  Serial.printf("TWAI Messages Bus errors: %i\n", twai_status.bus_error_count);
  Serial.printf("TWAI Messages ARB Lost: %i\n", twai_status.arb_lost_count);


  if (twai_status.msgs_to_rx >= 1)
  {
    if (twai_receive(&message, pdMS_TO_TICKS(10)) == ESP_OK)
      Serial.printf("Message received\n");
    else
    {
      Serial.printf("Failed to receive message\n");
      return;
    }

    //Process received message
    Serial.printf("ID is %d\n", message.identifier);
    for (int i = 0; i < message.data_length_code; i++)
    {
      Serial.printf("Data byte %d = %d\n", i, message.data[i]);
    }
  }
}

My platformio config:

Code: Select all

[env:esp32dev]
platform_packages = 
	framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.0-rc1
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
board = esp32dev
framework = arduino
board_build.mcu = esp32s2
; board_build.mcu = esp32
monitor_speed = 115200
upload_port = /dev/ttyUSB0
monitor_port = /dev/ttyUSB0
lib_deps = 
	buelowp/sunset@^1.1.3
	adafruit/Adafruit Si7021 Library@^1.4.0

noebl1
Posts: 6
Joined: Sun Aug 08, 2021 2:53 pm

Re: ESP32-S2 TWAI not receiving, but sending working fine, ESP32 same code works fine

Postby noebl1 » Mon Aug 16, 2021 9:15 pm

After searching apparently for the 100th time and not finding it, I found this issue: https://github.com/espressif/esp-idf/issues/5604

Who is online

Users browsing this forum: Bing [Bot] and 83 guests