TWAI stopped working after upgrade to New Arduino Core

zlomennypez
Posts: 2
Joined: Thu Feb 13, 2025 9:11 am

TWAI stopped working after upgrade to New Arduino Core

Postby zlomennypez » Sat Feb 15, 2025 7:04 pm

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.

lbernstone
Posts: 916
Joined: Mon Jul 22, 2019 3:20 pm

Re: TWAI stopped working after upgrade to New Arduino Core

Postby lbernstone » Sun Feb 16, 2025 6:02 pm

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.

Who is online

Users browsing this forum: No registered users and 65 guests