emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.
Other
534 stars 190 forks source link

modbusRTU with STM32L4 #359

Closed Rumen33 closed 1 month ago

Rumen33 commented 4 months ago

I am trying to use the modbus RTU library with STM32L431RTC6 processor and it looks like the pulse on the direction pin of the processor is not long enough to achieve successful data transmission. I am using v. 4.1.0 of the library, but I also tried 4.1.1, without solving the problem. The processor is running at 16MHz clock freq. Data transmission speed is 9600 bps. The code was also tested with ESP32 and works great there.

I succeed to solve the problem by adding the following into ModbusSettings.h:

if defined(ARDUINO_GENERIC_L431RCTX)

define MODBUSRTU_FLUSH_DELAY 20

endif

Is this a correct solution? Any support will be appreciated.

emelianov commented 1 month ago

Requirements of manipulating with MODBUSRTU_FLUSH_DELAY indicates that Serial.flush() returns prior to serial buffer to send to line. I'm afraid no quick way for fix its properly without deep dive to STM hardware|SDK.