Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modbus_rtu_set_serial_mode needs additional flags #742

Open
jan-kardell opened this issue Apr 22, 2024 · 1 comment
Open

modbus_rtu_set_serial_mode needs additional flags #742

jan-kardell opened this issue Apr 22, 2024 · 1 comment

Comments

@jan-kardell
Copy link

libmodbus version

all

OS and/or distribution

OpenWrt 21.02, Linux 5.4

Environment

arm 32-bit

sc16is752 UART

Description

It is not enough to to set the SER_RS485_ENABLED for hw assisted rs485 direction control. It is also necessary to set
either SER_RS485_RTS_AFTER_SEND or SER_RS485_RTS_ON_SEND. Some drivers check these flags and return a fails on the ioctl
call.

In my case, the sc16is752 UART hardware only supports SER_RS485_RTS_AFTER_SEND, and it is therefore necessary to set SER_RS485_RTS_AFTER_SEND and clear SER_RS485_RTS_ON_SEND in addition to setting SER_RS485_ENABLED. And that is enforced by the driver. There are probably other drivers that also do that.

Maybe these flags has been introduce in some specific Linux version, so that the Linux version has to be checked, but I have not examined that.

Actual behavior if applicable

<...>

Expected behavior or suggestion

<...>

Steps to reproduce the behavior (commands or source code)

<...>

libmodbus output with debug mode enabled

<...>

@jan-kardell
Copy link
Author

Just found #331.

Searching some more reveals that the sc16is7x driver do not call uart_get_rs485_mode(), and therefore do not have a default rs485 config, or a config from device tree (property rs485-rts-active-low).

Therefore neither SER_RS485_RTS_ON_SEND or SER_RS485_RTS_AFTER_SEND is set.

There are recent patches to fix that: https://lore.kernel.org/lkml/20230725142343.1724130-1-hugo@hugovil.com/T/

There are however cases where setting this in the device tree is not desirable, the device tree should describe the bord, not some external rs485-adapter that happens to be connected. So the need to support SER_RS485_RTS_ON_SEND and SER_RS485_RTS_AFTER_SEND remains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant