In my case, I found out that 4 ms delay was caused by xTaskList() or uxTaskGetSystemState() that calls vTaskSuspendAll() in its implementation.
Check if you don't call one of these functions every 5 sec.
Or maybe ESP_LOGx() could have similar effect, try to disable or prolong prints to console and check if the 40 ms delay occurs less frequently.
Alternatively, if you can modify HW, you can try to use some Paralel-in Serial-out shift register and convert it to some form of SPI communication.
How do interrupt execution work then? Do interrupts have its own set of CPU registers, so the current task's registers can stay untouched without any context switch?MicroController wrote: ↑Sat Sep 02, 2023 3:34 pmFortunately, running an ISR per se doesn't require a context switch between tasks.