ArduinoRS485 icon indicating copy to clipboard operation
ArduinoRS485 copied to clipboard

`setDelays()` is undocumented

Open PanzerFowst opened this issue 1 year ago • 4 comments

The library's public API includes a setDelays function:

https://github.com/arduino-libraries/ArduinoRS485/blob/9d5872eadbd3a1de8feca6b64f92cb2a08737540/src/RS485.h#L83

But this function is not mentioned in the documentation (Arduino library documentation).

The entire public API of the library must be documented.

An example sketch should be provided that demonstrates its usage, including whether it must be called before a begin() call, after, or does it not matter?

PanzerFowst avatar Jan 05 '24 18:01 PanzerFowst

I'm just analyzing the RS485 code. The postdelay seems to be necessary for driving the DE signal (enable transmitter in driver) because the _serial->write() returns before all bits are on the line. So the setting is dependent on the bitrate of the uart.

JojoS62 avatar Feb 06 '24 13:02 JojoS62

Yeah, that sounds consistent with my experience as well. I am setting the delay using a simple equation for Modbus:

    constexpr auto ModBaud{9600};
    constexpr auto bitduration{1.0f / ModBaud};
    constexpr auto charlen{11.0f};
    constexpr auto delay_us{bitduration * charlen * 3.5f * 1e6};

But it would be nice if the default values for delay could be calculated based on the baud of the RS485.

PanzerFowst avatar Feb 06 '24 18:02 PanzerFowst

Hi all. It seems this is going off topic. While it is very interesting, I will request that all further discussion on this issue thread be restricted exclusively to the subject of the missing documentation of the setDelays function.

You are welcome to submit separate issues for reports of bugs or feature requests.

General discussion is always welcome over on Arduino Forum:

https://forum.arduino.cc/

per1234 avatar Feb 07 '24 02:02 per1234

The postdelay is essential for the RS485 to work correctly. When the delay is too short, the driver is turning off DE too early and the message is corrupted. When is delay is too long, it blocks the receiving of the ACK. The delay is performed by a wait_us() which burns cpu cycles and blocks the system. The calculation of the delay time based on the baud rate is important, only the factor 3.5 is not necessary and makes it too long, one wordlength is enough.

I don't understand why this can be off topic, This library is used in Portenta Machine Control, which claims to be a professional product. Currently, I'm evaluating the PMC for usage in industrial environment. And there it needs reliable software and clear documentation. Answers like these do not help and will shorten my evaluation period.

JojoS62 avatar Feb 07 '24 14:02 JojoS62