Skip to content

MODBUS communication randomly broken due to misbehaving Serial.flush() function #5877

Closed
@garageeks

Description

@garageeks

Using arduino-esp32 1.0.6, the library ModbusMaster (https://github.com/4-20ma/ModbusMaster) works as intended.
Using arduino-esp32 2.0.0 or 2.0.1 it randomly stops communicating with the slave Modbus device.

I investigated with a scope and these are my findings:
RED LINE = TX signal, BLUE LINE = TX enable signal (tied to DE/NOT RE pins)

  1. Succesful transmission - the device replies as expected (Not seen here as I only have two channels)
    picoscope-success

  2. First failed transmission - enable signal stays high for a long time, preventing reception of the device answer
    picoscope-firstfail

  3. Subsequent failed transmission - enable signal is prematurely turned to LOW. The time it stays HIGH varies.
    picoscope-fail1
    picoscope-fail2
    picoscope-fail3

The mentioned library, when a packet is transmitted, turns HIGH the enable signal with preTransmission callback, write data to the serial port, flushes the serial port and then turns the enable signal LOW. Pretty straightforward. I assume Serial TX is buffered, then Serial.flush takes its time until the buffer is empty.

modbus-fail

Given the recent big overhaul of HardwareSerial and some other issues, I think there is a bug in the new implementation with 2.0.0 and 2.0.1 releases.

This is similar to #4603

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions