ESP32-C3-S32使用TWAI的问题

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

ESP32-C3-S32使用TWAI的问题

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

在使用esp-idf-v4.4的库及esp32-c3-s32模组的情况下,遇到twai功能的两个GPIO2/GPIO3无数据波形的情况,有朋友遇到过吗?如何解决
void app_main(void)
{
twai_message_t message;
esp_err_t err;
//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_500KBITS();
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)
{
ESP_LOGI(EXAMPLE_TAG, "Driver installed\n");
}
else
{
ESP_LOGI(EXAMPLE_TAG, "Failed to install driver\n");
return;
}

//Start TWAI driver
if (twai_start() == ESP_OK)
{
ESP_LOGI(EXAMPLE_TAG, "Driver started\n");
}
else
{
ESP_LOGI(EXAMPLE_TAG, "Failed to start driver\n");
return;
}
message.identifier = 0xAAAA;
message.extd = 1;
message.data_length_code = 8;
for (int i = 0; i < 8; i++)
{
message.data = 0x0A;
}

while(1)
{
//Queue message for transmission
err = twai_transmit(&message, portMAX_DELAY);
if (err == ESP_OK)
{
ESP_LOGI(EXAMPLE_TAG,"Message queued for transmission\n");
}
else
{
ESP_LOGI(EXAMPLE_TAG,"Failed to queue message for transmission\n");
twai_clear_transmit_queue();
}

vTaskDelay(pdMS_TO_TICKS(10000));
}
vTaskDelete(NULL);
}

Who is online

Users browsing this forum: No registered users and 102 guests