Hello!
I’m trying to implement a Modbus RTU communication, RS485 half-duplex.
This is my system:
- imx6q / Ixora (V1.2)
- Linux apalis-imx6-10887206 5.4.129-rt61-0+git.c43bc2d53067 #1 SMP PREEMPT_RT
- Kernel: linux-toradex-mainline
- I didn’t change the device tree.
I tried to follow the documentation, but it doesn’t work so far. Since this is not my area of expertise, I hope someone can give me some pointers.
First, I would like to use the X21 header on the Ixora board. If I understand it correctly, for my use case, that would be pin 3 (UART2_RS232_RXD) and pin 4 (UART2_RS232_RTS). Is this correct?
For testing, I followed the advice from this article to set the following flags:
struct serial_rs485 rs485conf;
/* Enable RS485 mode: */
rs485conf.flags |= SER_RS485_ENABLED;
/* Set logical level for RTS pin equal to 0 when sending: */
rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);
/* Set logical level for RTS pin equal to 1 after sending: */
rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
/* Enable receiver during sending, required for i.MX devices */
rs485conf.flags |= SER_RS485_RX_DURING_TX;
ioctl(fd, TIOCSRS485, &rs485conf);
I implemented a simple program using libmodbus to read a register from a server (slave) device. It doesn’t seem to be doing anything.
I will further experiment and test this myself, but it seems that I’m missing some basic information. Therefore, my questions are:
- Are the pins I’m using correct (without changing the device tree from the default)?
- Do I need to do something else to use RS485 half-duplex on my system, or should the above (ioctl) work already?
- How can I best debug this?
Many thanks in advance for any inputs.