<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

擴展USB連接

作者: 時(shí)間:2013-06-12 來(lái)源:網(wǎng)絡(luò ) 收藏
USB(通用串行總線(xiàn))是現在支持許多通用現成的外圍設備,如鍵盤(pán),鼠標,打印機和存儲設備等的公認作為首選的連接方案。對于致力于工業(yè)和消費市場(chǎng)的設備制造商來(lái)說(shuō),USB也成為滿(mǎn)足其連接至PC需求的一個(gè)優(yōu)先的選擇。事實(shí)上,對于任何一個(gè)使用標準的PC作為控制器設備的應用,USB接口的好處是顯而易見(jiàn)的。雖然大批量短生命周期的通用外設可以不使用USB接口,一些有更長(cháng)的生命周期的定制型應用則需要添加來(lái)解決現代PC缺乏傳統的連接接口的問(wèn)題。

在這些現代PC所不支持的接口中,RS-232串行接口是一個(gè)典型的例子,從軟件的角度看,RS-232相比USB更容易實(shí)現且同樣仍然滿(mǎn)足多種應用需求。但是大多數現代PC已經(jīng)去掉了RS-232接口。

簡(jiǎn)單的串口通信方案的成本往往低于復雜的替代產(chǎn)品,如RS-232接口成本低于USB接口。RS-232方案的基本組成部分包括一個(gè)UART和一個(gè)驅動(dòng)器和一個(gè)簡(jiǎn)單的握手協(xié)議,即使在資源非常有限的微控制器中也可以很容易地實(shí)現。而且RS–232接口的特性使其成為一個(gè)可以勝任惡劣的工作環(huán)境的強壯型短距離點(diǎn)對點(diǎn)通信解決方案。這樣的需求在許多工業(yè)控制或測量的實(shí)現中非常典型?;谶@些原因,RS-232接口依然活躍在許多應用領(lǐng)域。

由于現代PC缺乏對RS-232接口的支持,PC作為控制器的應用對RS-232接口的支持就顯得令人失望。而實(shí)現對RS-232接口外設支持的可選擇方案似乎很少:找到一個(gè)PC其裝有提供RS-232接口的PCI卡或重新把外圍設備設計為支持USB接口類(lèi)型。用USB替換RS-232接口需要大量的設計工作。這些影響不僅體現在硬件上,而且更重要的是給嵌入式軟件帶來(lái)非常巨大的變化。

現在還有第三個(gè)選擇可以用來(lái)在現代PC上支持RS-232接口外設。此種方式較之其他方式需要較少的工程方面工作并且保持傳統設備的完整性和穩定性。這種方式的好處是提供了一個(gè)USB和RS–232接口之間的透明轉換。FTDI公司的系列芯片即可支持這種方案,這些芯片解決了使用標準UART端口來(lái)實(shí)現嵌入式USB支持的相關(guān)復雜性問(wèn)題。該技術(shù)提供了一種支持傳統RS-232接口外設的簡(jiǎn)單及低成本的解決方案。圖1顯示小型PCB如何使用FTDI芯片來(lái)提供此種解決方案。

擴展USB連接

圖1:傳統RS-232 調制解調器連接到現代PC。


現在FTDI家族的第五代芯片支持USB 1.0和USB 2.0 協(xié)議(低速,全速和高速)。這些設備提供了一系列的異步和同步串行接口解決方案,包括UART接口( RS-232/RS-422/RS-485 )和FIFO 。除了集成在PCB級,這些芯片可用于制作PC與外設之間的USB到RS-232的接口轉換連接線(xiàn)。連接線(xiàn)內的芯片完成所有PC與外設之間的接口轉換工作。由于USB的波特率比RS–232的波特率高很多(6000:1),因此這些設備不僅需要提供兼容的USB接口,而且必須能夠對數據進(jìn)行緩沖,分析和重組來(lái)滿(mǎn)足RS – 232協(xié)議的規范。這些都是基于FTDI所專(zhuān)有的IP實(shí)現,包括一個(gè)USB協(xié)議引擎,一個(gè)UART控制器,一個(gè)串行接口引擎及一個(gè)USB收發(fā)器。圖2所示為其中一種芯片FT232R的機構框圖。

擴展USB連接

圖2:FT232R架構框圖。


運行在原有設備端的軟件并不需要改變,但是僅就所使用的COM端口而言,運行在PC端的應用程序需要知道正在使用的是而非RS-232連接。當一個(gè)USB到RS – 232轉換線(xiàn)連接到PC的 USB端口,PC的操作系統會(huì )創(chuàng )建一個(gè)虛擬的COM端口。應用程序通過(guò)這個(gè)虛擬的COM端口與USB接口進(jìn)行通信,而不需要對PC上的應用程序進(jìn)行任何修改。應用程序只需要知道轉接線(xiàn)所連接的具體的COM端口即可與之通信。外設的軟件或硬件則不需要任何修改。圖3所列的軟件代碼給出了一個(gè)例子來(lái)顯示應用程序如何確定與之相連的COM端口,同時(shí)它還給出一些配置UART的例程代碼 。

#include "stdafx.h"

#include

#include

#include "ftd2xx.h"

int main(int argc, char* argv[])

{

FT_HANDLE fthandle;

FT_STATUS res;

LONG COMPORT;

char COMx[5];

int n;

DCB dcb;

HANDLE hCommPort;

BOOL fSuccess;

/***********************************************************************

//Find the com port that has been assigned to your device.

/***********************************************************************/

res = FT_Open(0, fthandle);

if(res != FT_OK){

printf("opening failed! with error %dn", res);

return 1;

}

res = FT_GetComPortNumber(fthandle,COMPORT);

if(res != FT_OK){

printf("get com port failed %dn", res);

return 1;

}

if (COMPORT == -1){

printf("no com port installed n");

}

else{

printf("com port number is %dn", COMPORT);

}

FT_Close(fthandle);

/********************************************************/

// Open the com port assigned to your device

/********************************************************/

n = sprintf(COMx, "COM%d",COMPORT);

hCommPort = CreateFile(

COMx,

GENERIC_READ | GENERIC_WRITE,

0,

NULL,

OPEN_EXISTING,

FILE_ATTRIBUTE_NORMAL,

NULL

);

if (hCommPort == INVALID_HANDLE_VALUE)

{

printf("Help - failed to openn");

return(1);

}

printf("Hello World!n");

/********************************************************/

// Configure the UART interface parameters

/********************************************************/

fSuccess = GetCommState(hCommPort, dcb);

if (!fSuccess)

{

printf("GetCommStateFailed n", GetLastError());

return (2);

}

//set parameters.

dcb.BaudRate = 115200;

dcb.ByteSize = 8;

dcb.Parity = NOPARITY;

dcb.StopBits = ONESTOPBIT;

fSuccess = SetCommState(hCommPort, dcb);

if (!fSuccess)

{

printf("SetCommStateFailed n", GetLastError());

return (3);

}

printf("Port configured n");

/********************************************************/

// Writing data to the USB to UART converter

/********************************************************/

DWORD dwwritten = 0, dwErr;

char data_out[12] = "HELLO WORLD";

DWORD w_data_len = 12;

fSuccess = WriteFile(hCommPort, data_out, w_data_len, dwwritten, NULL);

if (!fSuccess)

{

dwErr = GetLastError();

printf("Write Failed n", GetLastError());

return (4);

}

printf("bytes written = %dn", dwwritten);

/********************************************************/

//Reading data from the USB to UART converter

/********************************************************/


char buf[256];

DWORD dwRead;

memset(buf,0,256);

if (ReadFile(hCommPort, buf, w_data_len, dwRead, NULL))

{

printf("data read = %sn", buf);

}

/********************************************************/

//Closing the device at the end of the program

/********************************************************/

CloseHandle(hCommPort);

getchar();

return 0;

}

PC上很容易實(shí)現USB 。絕大多數針對臺式機或筆記本電腦的操作系統,包括Linux,現在都支持USB作為其標準配置。但是在嵌入式設備中,USB接口使用仍然由其是否很容易被嵌入式設備中的微控制器支持所決定。這就意味著(zhù)要在微控制器上如集成UART,SPI和I2C接口一樣集成USB接口。這將使得微控制器變得更復雜也因此給設備集成制造商帶來(lái)成本的壓力。

然而,使用FTDI的USB接口芯片,嵌入式設備只需要使用微控制器上的UART接口與USB芯片進(jìn)行通信就可以實(shí)現USB接口的連接。如前所述,繁重的USB協(xié)議由FTDI器件中所集成的專(zhuān)用硬件和固件來(lái)負擔。因此現在通過(guò)一個(gè)標準的COM端口發(fā)送一些簡(jiǎn)單的指令,任何使用微控制器的嵌入式設備可以支持輕易的支

上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: 擴展 USB連接

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>