ubuntu 下使用串口工具(呕心沥血整理调试成功)

ubuntu 下使用串口工具

1.安装

sudo apt-get install minicom

2.查看所有串口

ls /dev/tty*

3.连接串口线,查看正在使用的串口。

grep tty

4.修改minicom配置。

sudo minicom -s 选择Serial port setup

这里重要的是以下几个选项:

A 设置使用哪个串口设备(因为一台电脑上的串口可能不止一个),注意这里输入的是ttyS0

E 设置波特率、数据位、奇偶校验位、停止位,这里依次是115200,8,N,1

F 这个选项的含义,在下不知,但是网上众多人都说此项必须选成no,否则可能不能通信

5.打开串口查看日志。

sudo minicom

6.dmesg | grep tty

ls /dev/tty*

[ 0.234657] printk: console [tty0] enabled [ 1.085899] 00:01: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A [ 5.663858] usb 1-6: pl2303 converter now attached to ttyUSB0

7.查看USB转串驱动

首先看自己的Ubuntu 版本是否自带了U转串驱动,倘若没有,这种方法对你的系统还不适用。执行命令#lsmod | grep usbserial,如果能打印出上边的信息,证明此版本的Ubuntu操作系统自带有U转串驱动(U转串芯片是PL2303)。

lsmod |grep usbserial lsmod |grep usbserial

usbserial 49152 3 pl2303

lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 067: ID 413c:2113 Dell Computer Corp. Bus 001 Device 040: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port Bus 001 Device 068: ID 1bcf:0053 Sunplus Innovation Technology Inc. Bus 001 Device 002: ID 148f:7601 Ralink Technology, Corp. MT7601U Wireless Adapter Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

8.退出

按下ctrl-a x 或者ctrl-a q可以退出minicom

可能是当前用户没有root权限。

ubuntu12.04使用USB转串口时出现权限不够问题,如下 Unable to open serial port /dev/ttyUSB0 权限不够 解决办法: 通过增加udev规则来实现。步骤如下: 创建文件/etc/udev/rules.d/70-ttyusb.rules 在文件内增加一行 KERNEL=="ttyUSB[0-9]*", MODE="0666"

如果没有权限,执行 cd /etc/udev sudo chmod 777 -R /udev

boe@boe-OptiPlex-5060:/etc/udev/rules.d$ dmesg | tail [296995.945244] pl2303 ttyUSB0: error sending break = -19 [296995.945466] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0 [296995.945636] pl2303 1-6:1.0: device disconnected [297013.708243] usb 1-6: new full-speed USB device number 46 using xhci_hcd [297013.861200] usb 1-6: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00 [297013.861205] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [297013.861208] usb 1-6: Product: USB-Serial Controller [297013.861211] usb 1-6: Manufacturer: Prolific Technology Inc. [297013.863788] pl2303 1-6:1.0: pl2303 converter detected [297013.864673] usb 1-6: pl2303 converter now attached to ttyUSB0

连接成功的信息 boe@boe-OptiPlex-5060:~$ dmesg | tail [ 420.459331] pl2303 1-6:1.0: pl2303 converter detected [ 420.460374] usb 1-6: pl2303 converter now attached to ttyUSB0 [ 420.732315] usb 1-12: new low-speed USB device number 7 using xhci_hcd [ 420.885943] usb 1-12: New USB device found, idVendor=1bcf, idProduct=0053, bcdDevice= 0.72 [ 420.885948] usb 1-12: New USB device strings: Mfr=0, Product=2, SerialNumber=0 [ 420.885951] usb 1-12: Product: USB Optical Mouse [ 420.892797] input: USB Optical Mouse Keyboard as /devices/pci0000:00/0000:00:14.0/usb1/1-12/1-12:1.0/0003:1BCF:0053.0004/input/input19 [ 420.952743] input: USB Optical Mouse Mouse as /devices/pci0000:00/0000:00:14.0/usb1/1-12/1-12:1.0/0003:1BCF:0053.0004/input/input20 [ 420.953088] input: USB Optical Mouse Consumer Control as /devices/pci0000:00/0000:00:14.0/usb1/1-12/1-12:1.0/0003:1BCF:0053.0004/input/input21 [ 420.953330] hid-generic 0003:1BCF:0053.0004: input,hidraw2: USB HID v1.10 Keyboard [USB Optical Mouse ] on usb-0000:00:14.0-12/input0

经验分享 程序员 微信小程序 职场和发展