Page 1 of 1

TWAI stopped working after upgrade to New Arduino Core

Posted: Sat Feb 15, 2025 7:04 pm
by zlomennypez
Hello.

I have used Twai configuration, which worked well:

Code: Select all

twai_timing_config_t timing_config = {
        
        .brp = 83,                          // Baud Rate Prescaler
        .tseg_1 = 6,                      // Time Segment 1 (BS1)
        .tseg_2 = 2,                       // Time Segment 2 (BS2)
        .sjw = 1,                          // Synchronization Jump Width
        .triple_sampling = false           // Disable triple sampling
    };


After update of ESP32 Arduino to latest core version it stopped working.

Twai twai_timing_config_t timing_config changed and now it should be

Code: Select all

twai_timing_config_t timing_config = {
        .clk_src = TWAI_CLK_SRC_DEFAULT,   // Clock Source
        .quanta_resolution_hz = 10000000,  // Quanta Resolution (10 MHz)
        .brp = 83,                          // Baud Rate Prescaler
        .tseg_1 = 6,                      // Time Segment 1 (BS1)
        .tseg_2 = 2,                       // Time Segment 2 (BS2)
        .sjw = 1,                          // Synchronization Jump Width
        .triple_sampling = false           // Disable triple sampling
    };
What should be the first 2 values for default, that it would work as before? Thank you for any help.

Re: TWAI stopped working after upgrade to New Arduino Core

Posted: Sun Feb 16, 2025 6:02 pm
by lbernstone
The clock source should pretty much always be default (unless you know it isn't :D)
If you use the quanta resolution, it overrides the brp value. If you want the timing exactly the same as in 4.x, then set quanta_resolution to 0.
https://docs.espressif.com/projects/esp ... bit-timing
You can compare IDF4 to IDF5
If you aren't sure how to calculate the timing value, I'd suggest using one of the macro values.