-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Open
Labels
Type: Feature requestFeature request for Arduino ESP32Feature request for Arduino ESP32
Description
Related area
twai on_rx_down never work
Hardware specification
ESP32S3 Module dev
Is your feature request related to a problem?
I user esp32s3 module dev board , I use Arduino ice to program .
I connect twai rx to tx pin , then it could self-test.
the tx gpis has data to output , but the on_rx_done was not be called,
this is the code:
#include "esp_twai.h"
#include "esp_twai_onchip.h"
#include "driver/twai.h"
twai_node_handle_t node_hdl = NULL;
volatile int recv_ok = 0;
int a = GPIO_NUM_NC;
uint8_t recv_buff[80];
bool twai_rx_cb(twai_node_handle_t handle, const twai_rx_done_event_data_t *edata, void *user_ctx)
{
twai_frame_t rx_frame = {
.buffer = recv_buff,
.buffer_len = sizeof(recv_buff),
};
if (ESP_OK == twai_node_receive_from_isr(handle, &rx_frame)) {
// receive ok, do something here
Serial.println("recv one frame!");
recv_ok = 1;
return true;
}else {
Serial.println("recv failed!");
recv_ok = -1;
return false;
}
}
bool twai_err_cb(twai_node_handle_t handle, const twai_error_event_data_t *edata, void *user_ctx) {
Serial.print("edata val:");
Serial.println(edata->err_flags.val,HEX);
return true;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Initializing ...");
twai_onchip_node_config_t cfg = {
.io_cfg = {.tx = GPIO_NUM_16,
.rx = GPIO_NUM_17,
},
.bit_timing = {.bitrate = 250000,},
.tx_queue_depth = 5,
.flags = {.enable_self_test = 1},
};
ESP_ERROR_CHECK(twai_new_node_onchip(&cfg, &node_hdl));
// twai_timing_advanced_config_t timing_config = {
// .brp = 16, // prescaler w/ 80MHz clk. 80MHz/16 => 5 MHz => 200 ns per quanta
// // (80 MHz / 16)/(250 kHz) = number of quanta aka slices per bit = 20
// // so 20 = 1 + tseg1 + tseg2
// // to sample at 80% => 1 _ 15 _ <sample> _ 4
// .prop_seg = 2, // first part = prop_seg+tseg1
// .tseg_1 = 13,
// .tseg_2 = 4,
// .sjw = 3, // adjustable, allows the controller to adjust the bit timing (i.e. from clock drift)
// .triple_sampling = false,
// };
// ESP_ERROR_CHECK(twai_node_reconfig_timing(node_hdl, &timing_config, NULL)); // 配置仲裁段波特率,NULL 表示不配置 FD 数据段波特率
twai_event_callbacks_t user_cbs = {
.on_rx_done = twai_rx_cb,
.on_error = twai_err_cb,
};
ESP_ERROR_CHECK(twai_node_register_event_callbacks(node_hdl, &user_cbs, NULL));
twai_mask_filter_config_t mfilter_cfg = {
.id = 0x00, // 0b 000 0001 0000
.mask = 0x00, // 0b 111 1111 0000 表示高7位严格匹配,低4位忽略,接收ID为
// 0b 000 0001 xxxx (16进制0x01x)
.is_ext = false, // 不接收扩展ID,只接收标准ID
};
ESP_ERROR_CHECK(twai_node_config_mask_filter(node_hdl, 0, &mfilter_cfg)); //配置过滤器0
ESP_ERROR_CHECK(twai_node_enable(node_hdl));
}
static uint8_t data[8] = {0x01,0x02,0x03,0xaa,0xaa,0xaa,0xaa,0xaa};
void loop() {
// put your main code here, to run repeatedly:
switch (recv_ok) {
case -1:
Serial.println("recv failed!");
recv_ok = 0;
break;
case 1:
Serial.println("recv success!");
recv_ok = 0;
break;
case 0:
Serial.println("recv not run!");
break;
}
twai_frame_t frame = {
.header={.id = 0x100,
.ide = false,
},
.buffer = data,
.buffer_len = sizeof(data)
};
ESP_ERROR_CHECK(twai_node_transmit(node_hdl, &frame, 0));
//Serial.println("A frame had sent!");
twai_node_status_t status;
twai_node_record_t sti;
twai_node_get_info(node_hdl , &status , &sti);
Serial.printf("tx_err_count:%d , rx_err_count:%d \n" , status.tx_error_count , status.rx_error_count);
delay(100);
}Describe the solution you'd like
wait for solution!
Describe alternatives you've considered
No response
Additional context
No response
I have checked existing list of Feature requests and the Contribution Guide
- I confirm I have checked existing list of Feature requests and Contribution Guide.
Metadata
Metadata
Assignees
Labels
Type: Feature requestFeature request for Arduino ESP32Feature request for Arduino ESP32