RS485 Read/Write Demo
1 Demo overview
This demo shows how to test the RS485 read/write function on the development board.
2 RS485 interface overview
The board has two RS485 interfaces, corresponding to UART7 and UART8 respectively. The wiring diagram for the UART7 interface is shown below.

3 Procedure
Open a terminal and copy the executable smdt_rs485_rw from this demo's bin directory (05-Development Materials\Software Development Materials\linux_demo\smdt_rs485_rw\bin) to the board's filesystem (the source code is available under the src path).
In the terminal, run the following commands to switch to the directory containing the smdt_rs485_rw executable.
#切换到 smdt_rs485_rw 可执行程序所在目录
cd ‘可执行文件所在目录’
#查看 smdt_rs485_rw 是否在该目录下
lsIf the executable smdt_rs485_rw is in the current directory, change its permissions.
#添加可执行权限
chmod +x smdt_rs485_rw
#查询是否修改成功
ls -ld smdt_rs485_rwAfter confirming the permission change succeeded, run ./smdt_rs485_rw -h to view the program's help information. Some default parameters set in this test script are as follows:
- device: /dev/ttyS7 (i.e. UART4)
- size: 1024 (the default receive length in read mode)
#查看帮助信息
./smdt_rs485_rw -hThe result is shown below:

Run the following commands for read mode and send mode respectively.
#RS485读取数据模式
./smdt_rs485_rw -d /dev/ttyS7 -r
#RS485发送数据模式
./smdt_rs485_rw -d /dev/ttyS7 -wRunning ./smdt_rs485_rw -d /dev/ttyS7 -w enters the send-input state; data is sent when you press Enter. The result is shown below.
Press Ctrl+Z to force-exit this mode.


Running ./smdt_rs485_rw -d /dev/ttyS7 -r enters receive mode; it receives data and finishes receiving when you press Enter or when the data-size limit is reached, then displays the data in the terminal window. The result is shown below.
Press Ctrl+Z to force-exit this mode.


4 Supplementary notes
The switching of RS485 send/receive modes is already integrated into the kernel driver — the user does not need to manually control GPIO to switch. Some kernel driver code related to the automatic RS485 mode switching is shown below:





