RAK3172 can't sleep if UART1 was used

I am using RAK3172 RUI 4.1.0 with UART1 connected to MAX485. If I read data from the RS485 sensor before calling api.system.sleep.all(5000), the module does not sleep 5000 but wakes up almost immediately. And calling api.system.sleep.all(5000) twice in a row means the module has actually slept for 5 seconds. What is happening. If the RS485 sensor has not been read before, the module sleeps for exactly 5 seconds. Please help me.
Node_RS485.ino (2.5 KB)
hw_modbus.cpp (4.6 KB)

Difficult to say without knowing your code and your actual hardware setup.

api.system.sleep.all() does wake up on events like data received on UART, LoRa/LoRaWAN event or external interrupts.
If it wakes up for one of these reasons, it does not go to sleep again by itself.