alejoseb / Modbus-STM32-HAL-FreeRTOS

Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS
GNU Lesser General Public License v2.1
560 stars 188 forks source link

Behavior of library when there is spurious noise on modbus at powerup #50

Closed brynwolfe closed 2 years ago

brynwolfe commented 2 years ago

My code uses this library by sending a command and immediately waiting for a response, so each transaction is one-to-one. However, I am seeing responses getting out of sync with requests by 5, i.e., a modbus request doesn't see the corresponding response for 5 subsequent transactions. I assume data in the RX buffer is due to some initial noise on the UART receive inputs as the modbus device on the other end of the wires is powering up.

Regardless of the cause, is there a recommended way to purge the receive ring buffer? Calling RingClear on the receive buffer (xRingBuffer) won't work reliably because it doesn't have the locks around it to block simultaneous interrupts.

alejoseb commented 2 years ago

Hi, The library automatically manages any spurious data received. Therefore, purging the ring buffer is not necessary under any circumstances. If you have a sample code where I can reproduce your issue I can take a look. Besides, be sure to handle the notification value returned by each modbus query. If the master does not receive an answer you should handle it, e.g., implementing a delay before sending another request or something like that.

brynwolfe commented 2 years ago

Sorry, I never saw a notification indicating you had responded. Thanks for the clarification.