esp-idf TWAI 接收包没应答导致can通信失败

fary_young
Posts: 11
Joined: Tue Dec 15, 2020 5:57 am

esp-idf TWAI 接收包没应答导致can通信失败

Postby fary_young » Tue Dec 15, 2020 6:07 am

使用ESP32-Ethernet-Kit开发板,按照esp-idf编程指南编写了can的接收通信。接收不应答导致通信失败。请问具体是什么问题
代码如下:
void app_main(void)
{
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();
if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
printf("Driver installed\n");
} else {
printf("Failed to install driver\n");
return;
}
if(twai_start() == ESP_OK) {
ESP_LOGI(EXAMPLE_TAG,"Driver started\n");
} else {
ESP_LOGI(EXAMPLE_TAG,"Failed to start driver\n");
return;
}
while(1){
//Queue message for transmission
twai_message_t message;
if (twai_receive(&message, pdMS_TO_TICKS(10000)) == ESP_OK) {
if(message.identifier == 0x0002){
if (message.extd) {
printf("Message is in Extended Format\n");
} else {
printf("Message is in Standard Format\n");
}
if (!(message.rtr)) {
for (int i = 0; i < message.data_length_code; i++) {
printf("Data byte %d = %d\n", i, message.data);
}
}
}else{
printf("err id:%d\n",message.identifier);
}
} else {
printf("Failed to receive message\n");
}
memset(message.data, 0, sizeof(message.data));
vTaskDelay(pdMS_TO_TICKS(1000));
}
if(twai_stop() == ESP_OK) {
ESP_LOGI(EXAMPLE_TAG,"Driver stopped\n");
} else {
ESP_LOGI(EXAMPLE_TAG,"Failed to stop driver\n");
return;
}
if (twai_driver_uninstall() == ESP_OK) {
printf("Driver uninstalled\n");
} else {
printf("Failed to uninstall driver\n");
return;
}
}

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

Re: esp-idf TWAI 接收包没应答导致can通信失败

Postby ESP_Dazz » Tue Dec 15, 2020 11:33 am

fary_young wrote: 使用ESP32-Ethernet-Kit开发板,按照esp-idf编程指南编写了can的接收通信。接收不应答导致通信失败。请问具体是什么问题
代码如下:
你指的"接收不应答"是总线上ESP32没有发ACK信号吗?

fary_young
Posts: 11
Joined: Tue Dec 15, 2020 5:57 am

Re: esp-idf TWAI 接收包没应答导致can通信失败

Postby fary_young » Wed Dec 16, 2020 1:06 am

是的,后来发现是需要外部收发器的原因,已经解决。谢谢

dpwangjun
Posts: 1
Joined: Mon Feb 26, 2024 1:06 am

Re: esp-idf TWAI 接收包没应答导致can通信失败

Postby dpwangjun » Mon Feb 26, 2024 1:07 am

请问你是怎么解决的,遇到了同样的问题

Who is online

Users browsing this forum: No registered users and 214 guests