Added fix for canbus
This commit is contained in:
16
main/can.cpp
16
main/can.cpp
@@ -280,7 +280,7 @@ void sendCanCommands()
|
||||
const auto status = twai_get_status_info(&status_info);
|
||||
const auto timestamp_after = espchrono::millis_clock::now();
|
||||
|
||||
if (result == ESP_ERR_TIMEOUT || (status == ESP_OK && status_info.bus_error_count > can_sequential_bus_errors))
|
||||
if ((result == ESP_ERR_TIMEOUT || status == TWAI_STATE_BUS_OFF) || (status == ESP_OK && status_info.bus_error_count > can_sequential_bus_errors))
|
||||
{
|
||||
++can_sequential_error_cnt;
|
||||
++can_total_error_cnt;
|
||||
@@ -314,6 +314,20 @@ void sendCanCommands()
|
||||
{
|
||||
ESP_LOGE(TAG, "ERROR: twai_stop() failed with %s", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
if (configs.canUninstallOnReset.value)
|
||||
{
|
||||
if (const auto err = twai_driver_uninstall(); err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "ERROR: twai_driver_uninstall() failed with %s", esp_err_to_name(err));
|
||||
}
|
||||
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_NUM_22,
|
||||
TWAI_MODE_NORMAL);
|
||||
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS();
|
||||
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
|
||||
if (const auto err = twai_driver_install(&g_config, &t_config, &f_config); err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "ERROR: twai_driver_install() failed with %s", esp_err_to_name(err));
|
||||
}
|
||||
}
|
||||
if (const auto err = twai_start(); err != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "ERROR: twai_start() failed with %s", esp_err_to_name(err));
|
||||
|
Reference in New Issue
Block a user