Summary of Linux serial port debugging

stty command

1. Serial configuration

stty -F /dev/ttyS1 raw 115200 cs8 -parenb -cstopb

/dev/ttyS1: serial port file descriptor
115200: baud rate 115200
cs8: data bit 8
-parenb: no parity bit
-cstopb: 1 stop bit
raw: display the original value without escaping. If raw is not added, the shell cannot display data sent from the serial port to the device.

stty --help help documentation:
insert image description here

N : set the input and output speeds to N bauds
to set the baud rate to N, for example 9600 4800

insert image description here
csN: set character size to N bits, N in [5…8]
set the data bit to N, such as cs8, cs7

[-]cstopb: use two stop bits per character (one with '-')
to set the stop bit:
cstopb: 2 stop bits
-cstopb: 1 stop bit

[-]parenb: generate parity bit in output and expect parity bit in input (generate parity bit in output and require parity bit in input) parenb enables the terminal to perform parity check, -parenb disables
it check
-parenb: no check digit

[-]parodd: set odd parity (or even parity with '-')
parenb parodd: odd parity
parenb -parodd: even parity

2. Serial port test

Serial port parameter configuration:
[root@/]# stty -F /dev/ttyS1 raw 4800 cs8 -parenb cstopb
[root@/]#
insert image description here
View PC configuration information:

The device sends, the serial port receives
insert image description here

insert image description here

Serial port sending, device receiving
shell monitoring device serial port
insert image description here

Serial port software sends data to the serial port
insert image description here

The device displays received data
insert image description here

References

Reference 1: RAW mode serial port setting under Linux
Reference 2: FreeBSD Manual Pages --stty
Reference 3: stty command description and usage explanation
Reference 4: stty command description and usage explanation

microcom-command

If you don't have microcom commands, try busybox.
insert image description here

Configure the serial port baud rate and open the serial port. Other serial port attributes (data bits, parity bits) can be set using stty.

insert image description here

Serial software configuration
insert image description here

The serial port software sends data, and the device receives

insert image description here
insert image description here

Device sends, serial port software receives:
insert image description here
insert image description here

退出 microcom:
Ctrl-x to exit.

References:

Reference 1: busybox microcom

minicom command

To be perfected

Guess you like

Origin blog.csdn.net/luotuo28/article/details/125896180