Closed ZaTeeman closed 10 months ago
hi, can you explain what is the meaning of the trace in red? if that is the master, you have to add delays, (i.e., vtaskDelay) between calls to ModbusQuery.
yes, the red track is the master, the green track is the slave’s response.
Do I understand correctly that the "ModbusQuery" command is just adding a message to the queue for sending? The sending itself is made by the library when it is ready (the communication line is free, all the necessary time intervals have been met, etc.)
My "ModbusQuery" is called in different threads, so adding "vtaskDelay" is not always possible.
How can I modify the library code to automatically add a delay between messages?
You can add a delay just after getting a new telegram from the queue here:
You can make it a configurable parameter adding it to the modbus handler structure here: https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/blob/861d511588915796447184e1e384c11becfb1466/MODBUS-LIB/Inc/Modbus.h#L173
That would be a better option so you can have different configurations for different serial ports working at different baudrates. In the case of TCP that should not be needed so adding a conditional statement to verify that the interface is USART-based is also needed. It can also be auto-calculated, but FreeRTOS does not provide enough granularity for a perfect delay, which is not a big deal either.
You can consider to submit a PR to add that as a functionality, if you can verify it is working as needed.
First of all thank you for your work
I am using modbus RTU master mode to communicate with several slaves. boudrate: 115200 use DMA microcontroller: stm32f407
Sometimes communication with some devices is lost. As a result of searching for the reason, it was discovered that the library makes an insufficient period of silence between messages (for speed 115200, the standard provides for at least 1.75ms of silence)![08912e08-f3f9-4401-a043-93cd087c9d33](https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/assets/58188750/aebe9bbe-4996-496b-9b95-88cba5202060)
I send messages from different threads using "ModbusQuery(&ModbusMaster, modbus_t_struct)"
Tell me how to set the correct silence time between messages?