TWAI not working after wakeup from deep-sleep, e.t.c.

jesper
Posts: 25
Joined: Thu Nov 09, 2017 4:38 pm

TWAI not working after wakeup from deep-sleep, e.t.c.

Postby jesper » Mon Sep 09, 2024 10:24 am

I have being using TWAI (J1939) in our project for a long time with (almost (more about that later)) no issues.
I have now added a deep-sleep in case of low battery and reapplying external power will wake up the ESP32 again.
That all works great.
However, the TWAI does NOT recover after deep-sleep wakeup.
Hitting the Reset Button works and everything runs fine.
So, I then tried letting the deep-sleep wakeup trigger a esp_restart().
That didn't work either, it's only a Core Reset.`
According to the ESP32 Technical Reference Manual, a RWDT System Reset, is equivalent to a System Reset (same as Power On).
So I tried that. Still no cigar.
There is SOMETHING that is different when using the Reset Button, compared to the other resets. But WHAT?
How can I get my TWAI back into 'virgin' reset/power up state.
(I tried a peripheral reset too, nope.)

And, I wrote "almost" up at the beginning, as there is a another TWAI issue.
To switch speeds dynamically, for implementing an "auto-speed" detector, I cycle between 3 speeds, 125, 250 and 500 kbps, every 5 seconds, until I start getting data.
That is done by calling twai_stop(), twai_driver_uninstall(), followed by a new twai_driver_install(&g_config, t_config, &f_config) and a twai_start().
This seems to work fine. Until it doesn't.
After a random time, usually several hours or even days, the twai_stop will bork, with an ESP_ERR_INVALID_STATE error.
How is this possible? There was no error installing the driver or starting TWAI, so how can it not be in the TWAI_STATE_RUNNING state?
This error obviously only happen if there is no TWAI input data, as it otherwise would "lock" to one of the speeds.

Would love for the Espressif experts to shine some light on these problems.

/Jesper
MagicMicros Co., Ltd. - Rayong, Thailand
Electronics design, PCB layout & programming.

Who is online

Users browsing this forum: Bing [Bot] and 194 guests