#### [[返回文档目录]](../index.html) [[查看原始页]](../content/%5BRaspbian%5D%20%E4%BD%BF%E7%94%A8%20UART%20%E4%BD%9C%E4%B8%BA%20Raspberry%20Pi%20%E7%9A%84%E7%BB%88%E7%AB%AF%20%C2%BB%20Technical%20Blog.html) # [Raspbian] 使用 UART 作为 Raspberry Pi 的终端 » Technical Blog 忍不住想拿 [Raspberry Pi](http://raspberrypi.org/ "Raspberry Pi") 作为开发板的冲动,于是败了一台。 Raspberry Pi 需要有一张 SD 卡,我拿手机上的 TF 卡加一张卡托,在上面装了个 [Raspbian](http://www.raspbian.org/ "Raspbian")。我的 TF 卡是 8G Class4 的 SanDisk SDHC,可以正常使用。按 [Rasbian 官方安装文档](http://www.raspbian.org/RaspbianInstaller "Raspbian Installer") 装的,果然很慢,花了我一晚上。 不仅写卡慢,读 mirror 也很慢。 安装的时候需要一台显示器和一个键盘。我不知道只用 UART 能不能搞定,以后有时间了试一下。 由于我给它的定位是一块开发板,所以我不想再使用它的显示器输出和键盘输入作为终端,因为我不一定到处都能找到这两件东西,比如我家就没有 USB 键盘。 我有一个 PL2303HX (Type A)的 USB 转串口, 按我以前的经验,有这个东西就能和 Raspberry Pi 通讯。但是网上有很多地方说,Raspberry Pi 的 UART 是 3.3v 的 CMOS 电平。一开始我不确定我的 PL2303HX 是 5v 的 TTL 还是 3.3v 的 CMOS,不敢插,怕烧坏板子。所以找来万用表量了下 TX-GND 和 RX-GND 的压差,发现都高达 4.5v。 在网上找了半天,发现一共有三种 USB 转串口的方案,分别是 PL2303,FTDI232 和 CP2102 三种。有人说 CP2102 可以用,FTDI232 也可以用,只有 PL2303 很少有人用。 终于在看到国内有大侠讲 PL2303 接 Raspberry Pi 的方法,再加上以前从来都是 54 TTL 与 CMOS,不管接什么设备都没有因为这个烧掉过板子的经验,认为应该是安全的。 按照 [eLinux 上的 P1(Raspberry Pi 上的那个排针)针脚定义](http://elinux.org/Rpi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29 "GPIO"),接上我的 USB 转串口: [?](http://dola.xinfan.org/?p=238#) <table border="0" cellpadding="0" cellspacing="0" style="display: table; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 45px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 693px;"><tbody style="display: table-row-group; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 45px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 693px;"><tr style="display: table-row; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 45px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 693px;"><td style="border: 0px none rgb(120, 120, 120); color: rgb(120, 120, 120); display: table-cell; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 45px; margin: 0px; outline: rgb(120, 120, 120) none 0px; padding: 0px; text-align: left; text-decoration: initial; width: 32px;"><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; color: rgb(120, 120, 120); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; outline: rgb(120, 120, 120) none 0px; padding: 0px 6.953125px 0px 13.90625px; text-align: right; text-decoration: initial; white-space: pre; width: 8.140625px; background-position: 0% 0%; background-repeat: repeat repeat;">1</div><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; color: rgb(120, 120, 120); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; outline: rgb(120, 120, 120) none 0px; padding: 0px 6.953125px 0px 13.90625px; text-align: right; text-decoration: initial; white-space: pre; width: 8.140625px; background-position: 0% 0%; background-repeat: repeat repeat;">2</div><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; color: rgb(120, 120, 120); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; outline: rgb(120, 120, 120) none 0px; padding: 0px 6.953125px 0px 13.90625px; text-align: right; text-decoration: initial; white-space: pre; width: 8.140625px; background-position: 0% 0%; background-repeat: repeat repeat;">3</div></td><td style="display: table-cell; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 45px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 661px;"><div style="display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 45px; margin: 0px; padding: 0px; position: relative; text-align: left; text-decoration: initial; width: 661px;"><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px 13.90625px; text-align: left; text-decoration: initial; white-space: pre; width: 633.1875px; background-position: 0% 0%; background-repeat: repeat repeat;"><code style="display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; white-space: pre;">TX    接 Pin6</code></div><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px 13.90625px; text-align: left; text-decoration: initial; white-space: pre; width: 633.1875px; background-position: 0% 0%; background-repeat: repeat repeat;"><code style="display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; white-space: pre;">RX    接 Pin8</code></div><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px 13.90625px; text-align: left; text-decoration: initial; white-space: pre; width: 633.1875px; background-position: 0% 0%; background-repeat: repeat repeat;"><code style="display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; white-space: pre;">GND   接 Pin10</code></div></div></td></tr></tbody></table> [![SAMSUNG](http://files.note.sdo.com/M5cEN~kg9smgLX0es01brH)](http://dola.xinfan.org/?attachment_id=243) *(外链图片未本地化)* 打开 minicom,设置为 115200 8N1,果断上电。 哈哈,看到 Raspberry Pi 的启动输出了。但是启动后没有终端给我用。即只能看到输出,不能输入,也没有登入提示。 这有点奇怪,能看到 USB 转串口上 TX 指示灯有闪烁,说明不应该是硬件的问题,研究了一下发现是 Raspbian 的配置问题。需要修改 Raspbian 上的 /etc/inittab 文件,加一行: [?](http://dola.xinfan.org/?p=238#) <table border="0" cellpadding="0" cellspacing="0" style="display: table; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 693px;"><tbody style="display: table-row-group; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 693px;"><tr style="display: table-row; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 693px;"><td style="border: 0px none rgb(120, 120, 120); color: rgb(120, 120, 120); display: table-cell; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; outline: rgb(120, 120, 120) none 0px; padding: 0px; text-align: left; text-decoration: initial; width: 32px;"><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; color: rgb(120, 120, 120); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; outline: rgb(120, 120, 120) none 0px; padding: 0px 6.953125px 0px 13.90625px; text-align: right; text-decoration: initial; white-space: pre; width: 8.140625px; background-position: 0% 0%; background-repeat: repeat repeat;">1</div></td><td style="display: table-cell; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; width: 661px;"><div style="display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px; position: relative; text-align: left; text-decoration: initial; width: 661px;"><div style="background-image: none; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(255, 255, 255); background-size: auto; display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; height: 15px; margin: 0px; padding: 0px 13.90625px; text-align: left; text-decoration: initial; white-space: pre; width: 633.1875px; background-position: 0% 0%; background-repeat: repeat repeat;"><code style="display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 15.296875px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; margin: 0px; padding: 0px; text-align: left; text-decoration: initial; white-space: pre;">T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100</code></div></div></td></tr></tbody></table> 再启动,终于可以得到亲切的登陆提示了。 后来还发现一件事情,使用 USB 转串口的 5v 输出接 Raspberry Pi 的 Pin2 或者 Pin4 就能给 Pi 供电,也就是说不需要 Micro USB 数据线了。