74 static int next_twai_ctrl_num = 0;
75 if (
static_cast<unsigned>(next_twai_ctrl_num) >= SOC_TWAI_CONTROLLER_NUM) {
76 ESP_LOGW(TAG,
"Maximum number of esp32_can components created already");
82 twai_mode_t twai_mode = TWAI_MODE_NORMAL;
84 twai_mode = TWAI_MODE_LISTEN_ONLY;
85 ESP_LOGI(TAG,
"CAN bus configured in LISTEN_ONLY mode (passive, no ACKs)");
87 twai_mode = TWAI_MODE_NO_ACK;
88 ESP_LOGI(TAG,
"CAN bus configured in NO_ACK mode (transmit without requiring ACK)");
91 twai_general_config_t g_config =
92 TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t) this->
tx_, (gpio_num_t) this->
rx_, twai_mode);
93 g_config.controller_id = next_twai_ctrl_num++;
94 g_config.alerts_enabled = TWAI_ALERT_ERR_PASS | TWAI_ALERT_ERR_ACTIVE | TWAI_ALERT_BUS_OFF |
95 TWAI_ALERT_BUS_RECOVERED | TWAI_ALERT_RX_QUEUE_FULL;
103 twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
104 twai_timing_config_t t_config;
106 if (!get_bitrate(this->
bit_rate_, &t_config)) {
113 if (twai_driver_install_v2(&g_config, &t_config, &f_config, &(this->
twai_handle_)) != ESP_OK) {
189 twai_status_info_t twai_status;
192 status.bus_off = (twai_status.state == TWAI_STATE_BUS_OFF) || (twai_status.state == TWAI_STATE_RECOVERING);
193 status.rx_error_counter = twai_status.rx_error_counter;
194 status.tx_error_counter = twai_status.tx_error_counter;
196 status.tx_failed_count = twai_status.tx_failed_count;
197 status.rx_missed_count = twai_status.rx_missed_count;
198 status.rx_overrun_count = twai_status.rx_overrun_count;
199 status.arb_lost_count = twai_status.arb_lost_count;
200 status.bus_error_count = twai_status.bus_error_count;
202 ESP_LOGD(TAG,
"failed to get CAN status");