Raspberry Pi 485 to USB serial port debugging tutorial

Step 1: Wiring method: 485 to USB

Pay attention to whether the wiring port corresponds to: A1B1

Step 2: Check the serial port configuration—whether the mapping relationship is correct

命令:
    ls -l /dev

serial0 is the serial port mapped by GPIO. The default is ttyS0, which is the mini serial port. serial1 is the serial port mapped by the onboard Bluetooth. The default is ttyAMA0, which is the hardware serial port.

When the serial communication is enabled without any settings, the default serial communication uses the "mini serial port". If you want to use it in the project, in order to stabilize the communication, you need to swap the default mapping between "hardware serial port" and "mini serial port".

serial0 is mapped to ttyAMA0, serial1 is mapped to ttyS0

使用以下命令编辑 /boot 目录下的config.txt文件:
    sudo nano /boot/config.txt
在文本末尾加上如下一行代码:
    dtoverlay=pi3-miniuart-bt

Step 3: Close the serial console

 

Step 4: /boot/cmdline.txt file configuration

命令:
    sudo nano /boot/cmdline.txt
在其中添加该句:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes rootwait quiet spla>

Step 5: /boot/config.txt file configuration

命令:
    sudo nano /boot/config.txt
在最后添加串口开启,并打开指定串口
    enable uart=1
    dtoverlay=pi3-miniuart-bt,core_freq=250
    dtoverlay=uart4
    dtoverlay=uart3

Replenish:

查看目前已经打开哪些串口命令:
    ls /dev/ttyAMA*
或
     python -m serial.tools.list_ports

查看映射关系命令:
    ls -l /dev/serial*

重启命令:sudo reboot

mode 1

After connecting, open the device manager to check whether the serial port is normal

Debugging tool: MobaXterm_Personal_10.4

Use the python test code on the raspberry pie to debug

import serial
port = "/dev/ttyAMA2"
usart = serial.Serial(port,9600)
usart.flushInput()
print("serial test:BaudRate=9601")
usart.write("please\t".encode("utf-8"))

while True:
    if(usart.inWaiting()>0):
        receive = usart.read(1)
        usart.wirte("senf:".encode("utf-8"))
        usart.write(receive)
        usart.write("\r".encode("utf-8"))
        print(receive)

Example of a successful test:

debug 2

Reference article: Raspberry Pi Quick Start from Scratch Lecture 9 - Serial Port

Debugging tools: SSCOM, Raspberry Pi minicom

1) Download minicom

sudo apt-get install minicom

2) Confirm the hardware connection

After connecting, open the device manager to check whether the serial port is normal

2) run minicom

sudo minicom -D /dev/ttyAMA2 
// 默认波特率为115200,-D代表端口,/dev/ttyAMA2 类似于windows中的COM口

3) Open the serial port assistant on the PC side

Open the serial port assistant, set the baud rate and com port.

 4) PC and Raspberry Pi send and receive data to each other

Input a string in the minicom window to send it to the PC, and the window does not display the string entered by the keyboard by default. Send the character string on the PC side, and it will be displayed in the minicom window.

Tips for using minicom: 1: Enter crtl+A, and then enter E to open the serial port sending display (display is turned off by default), and then operate again to hide the display. 2: Enter crtl+A, then enter Q, Enter to exit the minicom window.

 

Guess you like

Origin blog.csdn.net/beiye_/article/details/130892323