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

發佈了9 篇原創文章 · 獲贊 2 · 訪問量 2050
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章