Hello
I’m developing a driver and application running on ESP32-P4, that connects to an equipment over Modbus. Therefor I’m using the library “ModbusMaster” (doesn’t seem maintained anymore) and LVGL for the GUI part which is already developed.
I don’t have the Modbus equipment yet. Which isn’t a problem because I also have to take into account the use case where the communication fails.
I’m using this task/LVGL timer to refresh the GUI:
lv_timer_t * task1 = lv_timer_create(
rexModulesUpdate
, 20000, NULL);
Now the problem:
With this refresh task (which try to connects to the modbus equipment), the GUI is not usable, the display framerate drops to 0 (CPU load is 0 too), and the touch screen doesn’t respond or only after a long time.
Even if a reduce the timeout of the serial port to 20ms (because as said, there is no equipment connected yet), there is no changes.
Now the question:
1. Is this related to the single thread nature of Arduino? In other words I’m stuck.
2. Is it the Modbus library’s fault?
Thank you
You seem concerned by the fact the library is untouched for 9 yrs. Have you looked at the ArduinoModBus library by Arduino. It is documented in the Arduino Library section
https://docs.arduino.cc/libraries/arduinomodbus/
Well, I read that ArduinoModbus wasn’t compatible with the ESP32s, so I choose a different lib :-/
That is an excellent reason.
Try replacing rexModulesUpdate with an empty function. I suspect that the problem is that LVGL wants a fast refresh and you’re causing it to block for too long. I vaguely remember running into a similar issue but I can’t think of the specifics right now
Yes it’s the problem indeed.
The Modbus is running on the same thread as the GUI, that’s why.
Now the question is if there is a Modbus driver out there that behaves better 
EDIT:
Well there may be a workaround for this problem. I may check if the Modbus connection has timedout, if so, I stop sending new requests for a certain time. It’s at the driver level I think.
Is there any reason you can’t run Modbus on a different thread
Two reasons:
- Arduino doesn’t support multi-threading (I think)
- My knowledge

I’m gonna pause for some time the fetching of data over Modbus if there is a timeout. It will periodically cause some lag of the GUI, but should be ok.
If you’re running on an ESP32 with the arduino IDE, it’s running FreeRTOS under the hood. Just start a new task to manage your Modbus communication.
void rexModulesUpdate(void *pvParameter); ... xTaskCreate(&rexModulesUpdate, "rexModulesUpdate", 2048, NULL, 1, NULL);
1 Like
Now I’m getting resets of the MCU after some seconds of running 
E (31125) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (31125) task_wdt: - IDLE0 (CPU 0)
E (31125) task_wdt: Tasks currently running:
E (31125) task_wdt: CPU 0: rexModulesUpdat
E (31125) task_wdt: CPU 1: loopTask
E (31125) task_wdt: Aborting.
E (31125) task_wdt: Print CPU 0 (current core) registers
Do I have to use semaphores, mutex and co in my code?
It’s beyond my knowledge 
Something in your modbus code is blocking for too long and causing the watchdog to time out.
I have placed a yield() in my driver task and it seems to work… for now 