《電子技術(shù)應(yīng)用》
您所在的位置:首頁(yè) > 通信與網(wǎng)絡(luò) > 設(shè)計(jì)應(yīng)用 > USB通信系統(tǒng)設(shè)計(jì)方案
USB通信系統(tǒng)設(shè)計(jì)方案
來(lái)源:維庫(kù)電子
摘要:   USB(Universal Serial Bus)是一種目前通用的串行總線技術(shù),它是通過(guò)PCI總線和PC的內(nèi)部系統(tǒng)數(shù)據(jù)線連接,實(shí)現(xiàn)數(shù)據(jù)的傳送,具有即插即用的功能,支持熱拔插,設(shè)備間線纜的長(zhǎng)度可達(dá)5 m左右。
關(guān)鍵詞: PCI USB PC
Abstract:
Key words :

  1 USB通信技術(shù)

  USB(Universal Serial Bus)是一種目前通用的串行總線技術(shù),它是通過(guò)PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI" title="PCI">PCI總線和PC的內(nèi)部系統(tǒng)數(shù)據(jù)線連接,實(shí)現(xiàn)數(shù)據(jù)的傳送,具有即插即用的功能,支持熱拔插,設(shè)備間線纜的長(zhǎng)度可達(dá)5 m左右。

  USB接口信號(hào)線有4條線,兩條是電源線與地線(Vbus與GND),兩條是以差分方式產(chǎn)生的信號(hào)線(D+與D-),從而實(shí)現(xiàn)了主機(jī)系統(tǒng)與USB設(shè)備之間的數(shù)據(jù)通信,見(jiàn)圖1。

   USB通信數(shù)據(jù)流

  圖1 USB通信數(shù)據(jù)流

  USB總線121技術(shù)是基于分組交換方式的總線通信。首先把數(shù)據(jù)分成若干塊,然后在每塊數(shù)據(jù)前添加上同步信號(hào)、包標(biāo)識(shí),后面添加上CRC校驗(yàn),形成USB封包。USB總線通信使用一種差分的輸出驅(qū)動(dòng)器來(lái)控制數(shù)據(jù)信號(hào)在USB電纜上的發(fā)送,即通過(guò)控制D+和D一線從空閑態(tài)到相反的邏輯電平,實(shí)現(xiàn)源端口的包發(fā)送。包發(fā)送結(jié)束后,D+和D-上的輸出驅(qū)動(dòng)器均處于高阻抗?fàn)顟B(tài)。

  2 USB通信系統(tǒng)設(shè)計(jì)

  2.1 硬件設(shè)計(jì)

  USB通信接口是連接Pc機(jī)和汽車尾氣檢測(cè)儀內(nèi)嵌單片機(jī)通信的橋梁,目前采用USB接口芯片來(lái)實(shí)現(xiàn)PC機(jī)與單片機(jī)AT89C5 1之間的連接是一種比較好的方法。

  由于汽車尾氣檢測(cè)系統(tǒng)內(nèi)嵌單片機(jī)是采用串口(TXD、RXD)以RS232方式進(jìn)行通信的,所以USB芯片與單片機(jī)AT89C51之間的連接方式也必須是RS232串口通信方式。因此,本文采用PROLIFIC公司推出的可實(shí)現(xiàn)USB接口轉(zhuǎn)RS232串口的轉(zhuǎn)換芯片PL一2303HX。根據(jù)汽車尾氣檢測(cè)儀USB通信系統(tǒng)設(shè)計(jì)要求,USB通信接口電路設(shè)計(jì)如圖2所示。

  USB通信接口

  圖2 USB通信接口

  USB插頭與USB芯片間的連接通過(guò)USB—D+、USB—D一、GND和VO一3.3這4個(gè)端點(diǎn)實(shí)現(xiàn),由于USB芯片PL2303HX支持類RS232接口,含有全雙工發(fā)送和接收(RXD、TXD)串口,所以,PL2303HX芯片與單片機(jī)AT89C51的RS232串口間直接可以用3根線RXD、TXD、GND連接,即USB芯片PL2303HX的RXD、TXD和GND分別與單片機(jī)AT89C51的TXD、RXD和GND連接,雙方都可發(fā)送和接收。

  2.2 軟件設(shè)計(jì)

  2.2.1 通信方式

  本文USB通信系統(tǒng)采用異步半雙工通信方式,即通信的某一方發(fā)送和接收交替進(jìn)行。通信的數(shù)據(jù)格式為每幀10位,包括1位起始位、8位數(shù)據(jù)位和1位停止位,見(jiàn)圖3。

  字節(jié)傳輸序列

  圖3 字節(jié)傳輸序列

  這里設(shè)置單片機(jī)串行口采用T作模式l,為10位異步通信,片內(nèi)定時(shí)器Tl作為波特率發(fā)生器,波特率為2400bps;由串行口控制寄存器SCON的工作模式選擇位SM0、SMI,分別設(shè)為0和l,從而設(shè)置其串行口為模式l;當(dāng)定時(shí)器/計(jì)數(shù)器Tl控制寄存器TMOD中C/T=0和M1M0=10時(shí),AT89C51定時(shí)器/計(jì)數(shù)器Tl為定時(shí)器模式,設(shè)置為方式2。作為波特率發(fā)生器,其波特率表示為:

  

  則:定時(shí)器Tl的初值應(yīng)設(shè)置為11Ll=THI=F3H,另外應(yīng)禁止定時(shí)器Tl中斷,以免因定時(shí)器T1溢出而產(chǎn)生不必要的中斷。

  2.2.2 通信協(xié)議

  進(jìn)行通信之前,通信雙方首先要根據(jù)系統(tǒng)的功能要求制訂某種特定的通信協(xié)議,然后才能編寫(xiě)相應(yīng)的通信程序。本文通信協(xié)議:

 ?、偻ㄐ烹p方均使用2 400 bps的速率傳送數(shù)據(jù),PC機(jī)與AT89C51均工作于串口方式l(1位起始位、8位數(shù)據(jù)位、l位停止位)。

  ②AT89C51在發(fā)送和接收數(shù)據(jù)時(shí),采用串口中斷方式。

 ?、跴C機(jī)發(fā)出數(shù)據(jù)采集命令(握手信號(hào)),單片機(jī)AT89C5l串口收到握手信號(hào)后,立即將AT89C51內(nèi)存存放的檢測(cè)數(shù)據(jù)經(jīng)過(guò)USB通信接口發(fā)送到PC機(jī),一次數(shù)據(jù)采集完成。

USB通信程序流程e#

 

  2.2.3 通信程序流程

  通信程序涉及到PC機(jī)通信程序和AT89C51串口通信中斷程序,上位機(jī)(PC機(jī))發(fā)出數(shù)據(jù)采集命令,下位機(jī)(單片機(jī)AT89C51)收到握手信號(hào)后,將數(shù)據(jù)傳回PC機(jī),從而完成一次數(shù)據(jù)采集,圖4和圖5是兩個(gè)通信程序的流程圖。

  PC機(jī)通信子流程

  圖4 PC機(jī)通信子流程

  單片機(jī)串口中斷子流程

  圖5 單片機(jī)串口中斷子流程

  3 結(jié)語(yǔ)

  本文設(shè)計(jì)的USB通信系統(tǒng)已在汽車尾氣檢測(cè)儀數(shù)據(jù)通信中得到了很好的應(yīng)用。該系統(tǒng)具有采集數(shù)據(jù)準(zhǔn)確可靠、使用靈活方便等優(yōu)點(diǎn),這種用USB通信技術(shù)取代傳統(tǒng)串口通信的方法切實(shí)可行,有望在其他的智能儀器、儀表設(shè)備中得到借鑒和推廣應(yīng)用。
 

此內(nèi)容為AET網(wǎng)站原創(chuàng),未經(jīng)授權(quán)禁止轉(zhuǎn)載。