CH554G如何驅(qū)動XR21V1410芯片?

現(xiàn)在打算用CH554G做一個轉(zhuǎn)接板,需要驅(qū)動XR21V1410芯片,找了倒程只有PL2302,CH340,CP2012的,不知道XR21V1410如何設(shè)置串口參數(shù),是否可以提供解決方法?怎么組SETUP包,應(yīng)該按什么樣的順序發(fā)送SETUP包?

如果是通過USB通訊的話,可以先接入電腦,通過電腦端USB抓包工具看一下操作流程。然后單片機模擬這個流程操作USB設(shè)備。


有沒有什么文檔可以說明這個過程如何分析操作的?現(xiàn)在用Bus Hound 抓包也不會看,有點頭大j_0064.gif


自己搞定了,因為自己的需求很簡單,就是透傳USB口和串口的數(shù)據(jù),9600的波特率,停止位-1,奇偶校驗-無,數(shù)據(jù)位-8。

還是看芯片的規(guī)格書,不需要插電腦上用USB數(shù)據(jù)抓包,用的原廠的例程,然后找到芯片的PID,VID,再按著例程的驅(qū)動CH340的方式來寫匹配PID,VID,匹配上了后設(shè)置波特率,根據(jù)規(guī)格書來組SETUP包,其中發(fā)SETUP包的時候,剛開始用FOR循環(huán)發(fā)會有問題,后面改成一條條好就可以,花了很多時間來了解USB的相關(guān)內(nèi)容,其實例程已經(jīng)做好了很多前面的工作,只要自己組SETUP包,然后發(fā)送就可以正常運行起來了。參考了這個文章的思路http://www.findthetime.net/bbs/thread-72287-1.html

下面是程序改動的地方:

USBHOST_IF.C文件

#define XR21V1410_VENDOR_ID0X04E2 //ADD by sean增加VID

#define XR21V1410_PRODUCT_ID?0X1410 //ADD by sean增加PID


const UINT16 XR21V1410_ID_Table[]={XR21V1410_VENDOR_ID,XR21V1410_PRODUCT_ID,}; //ADD by sean 增加表


//配置XR21V1410波特率 ,成功返回0

UINT8 XR21V1410_Baud_Config(UINT32 baud)

{?

UINT8 s=0;

//UINT16 i=0,j=0;

/*UINT8 XR21V1410_Setup_Packet[32]=

{

0x40,0x00,0x10,0x00,0X01,0x04,0x00,0x00,//FIFO_ENABLE = 0x1 // Enable TX FIFO

0x40,0x00,0x03,0x00,0X03,0x00,0x00,0x00,//UART_ENABLE = 0x3 // Enable TX and RX of that channel

0x40,0x00,0x10,0x00,0X03,0x04,0x00,0x00,//FIFO_ENABLE = 0x3 // Enable RX FIFO

0x40,0x00,0x03,0x00,0X03,0x00,0x00,0x00,//使能TX,RX

//0x40,0x00,0x04,0x00,0x88,0x00,0x00,0x00,//波特率時鐘除數(shù)0

//0x40,0x00,0x05,0x00,0x13,0x00,0x00,0x00,//波特率時鐘除數(shù)1

//0x40,0x00,0x06,0x00,0x00,0x00,0x00,0x00,//波特率時鐘除數(shù)2

//0x40,0x00,0x07,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)TX查找表的索0

//0x40,0x00,0x08,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)TX查找表的索1

//0x40,0x00,0x09,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)RX查找表的索0

//0x40,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)RX查找表的索1

//0x40,0x00,0x0B,0x00,0x08,0x00,0x00,0x00 //停止位-1,奇偶校驗-無,數(shù)據(jù)位-8

};*/

#if DE_PRINTF

? ? ? ? ? ? printf( "XR21V1410_Baud_Config START by sean\n " ); //測試是否程序運行到此處 by sean

printf("ThisUsbDev815.GpVar0=x%02X? \n",(UINT16)(ThisUsbDev.GpVar0));? ? ? ? ? ? ? ? ? ? // 可能是斷開了

printf("ThisUsbDev816.GpVar1=x%02X? \n",(UINT16)(ThisUsbDev.GpVar1));? ? ? ? ? ? ? ? ? ? // 可能是斷開了

printf("ThisUsbDev817.GpVar2=x%02X? \n",(UINT16)(ThisUsbDev.GpVar2));? ? ? ? ? ? ? ? ? ? // 可能是斷開了

#endif

/*while(j<32)

?{

for(i=0;i<8;++i)

{

TxBuffer[i]=XR21V1410_Setup_Packet[j];

++j;

#if DE_PRINTF

? ? ?printf( "TxBuffer[%d]=x%02X \n", j,(UINT16)( TxBuffer[i] )? ); //測試是否程序運行到此處 by sean

#endif

}

i = 0;

s = HostCtrlTransfer( NULL, NULL );

?}

*/

//0x40,0x00,0x10,0x00,0X01,0x04,0x00,0x00,//FIFO_ENABLE = 0x1 // Enable TX FIFO

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x10;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x01;?

TxBuffer[5] = 0x04;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x03,0x00,0X03,0x00,0x00,0x00,//UART_ENABLE = 0x3 // Enable TX and RX of that channel

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x03;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x03;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x10,0x00,0X03,0x04,0x00,0x00,//FIFO_ENABLE = 0x3 // Enable RX FIFO

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x10;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0X03;?

TxBuffer[5] = 0x04;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x03,0x00,0X03,0x00,0x00,0x00,//使能TX,RX

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x03;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x03;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x04,0x00,0x88,0x00,0x00,0x00,//波特率時鐘除數(shù)0

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x04;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x88;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x05,0x00,0x13,0x00,0x00,0x00,//波特率時鐘除數(shù)1

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x05;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x13;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x06,0x00,0x00,0x00,0x00,0x00,//波特率時鐘除數(shù)2

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x06;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x00;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x07,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)TX查找表的索0

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x07;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x00;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x08,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)TX查找表的索1

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x08;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x00;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x09,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)RX查找表的索0

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x09;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x00;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,//波特率時鐘余數(shù)RX查找表的索1

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x0A;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x00;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?

//0x40,0x00,0x0B,0x00,0x08,0x00,0x00,0x00 //停止位-1,奇偶校驗-無,數(shù)據(jù)位-8

TxBuffer[0] = 0x40;

TxBuffer[1] = 0x00;

TxBuffer[2] = 0x0B;

TxBuffer[3] = 0x00;

TxBuffer[4] = 0x08;?

TxBuffer[5] = 0x00;

TxBuffer[6] = 0x00;

TxBuffer[7] = 0x00;

s = HostCtrlTransfer( NULL, NULL );?


#if DE_PRINTF

? ? ? ? ? ? printf( "XR21V1410_Baud_Config END by sean\n " ); //測試是否程序運行到此處 by sean

?printf("ThisUsbDev832.GpVar0=x%02X? \n",(UINT16)(ThisUsbDev.GpVar0));? ? ? ? ? ? ? ? ? ? // 可能是斷開了

printf("ThisUsbDev833.GpVar1=x%02X? \n",(UINT16)(ThisUsbDev.GpVar1));? ? ? ? ? ? ? ? ? ? // 可能是斷開了

printf("ThisUsbDev834.GpVar2=x%02X? \n",(UINT16)(ThisUsbDev.GpVar2));? ? ? ? ? ? ? ? ? ? // 可能是斷開了

#endif

return( s );

}


InitRootDevice函數(shù)匹配芯片PID,VID,進行波特率設(shè)置


if( MatchID(dev_vid,dev_pid,XR21V1410_ID_Table,sizeof(XR21V1410_ID_Table)/sizeof(UINT16)) )? ?//XR21V1410 //ADD by sean

{

ThisUsbDev.DeviceType = DEV_TYPE_XR21V1410;

//初始化波特率參數(shù)(類命令)

s = XR21V1410_Baud_Config(Comm_Baud);

if(s==ERR_SUCCESS)

{

ThisUsbDev.DeviceStatus = ROOT_DEV_SUCCESS;? ? ? ? ? ? ? ? ? ? ? ? //設(shè)備初始化成功

return ERR_SUCCESS;

}

? ? ? ? ?}


DEBUG.C

#define? DE_PRINTF? ? ?1 //打開調(diào)試信息 by sean

main.c

//#pragma? NOAREGS //屏蔽編程命令 by sean

/*? //屏蔽? dataflash讀取設(shè)置參數(shù)功能 by sean

//ReadDataFlash(0,4,(UINT8 *)&Comm_Baud); //屏蔽從dataflash讀取參數(shù),并配置? 功能 by sean

Comm_Baud = 9600; //手動設(shè)置波特率為9600 by sean


寄存器說明REGISTER?NAME0x40 XR_SET_REG0val address0registerblock00寄存器值功能UART管理器寄存器 啟用寄存器描述(讀/寫)Enable TX FIFO0x400x000x100x000X010x040x000x00FIFO_ENABLE = 0x1 // Enable TX FIFO
Enable TX and RX0x400x000x030x000X030x000x000x00UART_ENABLE = 0x3 // Enable TX and RX of that channel
Enable RX FIFO0x400x000x100x000X030x040x000x00FIFO_ENABLE = 0x3 // Enable RX FIFOUART寄存器 啟用寄存器描述(讀/寫)Enable UART TX RX0x400x000x030x000X030x000x000x00使能TX.RX時鐘除數(shù)0寄存器描述(讀/寫) 48000000 / Baud RateCLOCK_DIVISOR00x400x000x040x000x880x000x000x00波特率115200=416,波特率9600=5000,?10001000?時鐘除數(shù)1寄存器描述CLOCK_DIVISOR10x400x000x050x000x130x000x000x0000010011時鐘除數(shù)2寄存器描述CLOCK_DIVISOR20x400x000x060x000x000x000x000x0000000000( ( ( 48000000 / Baud Rate ) - CLOCK_DIVISOR ) * 32)TX_CLOCK_MASK00x400x000x070x000x000x000x000x00((48000000/9600)-5000)*32=0TX時鐘索引(讀/寫)TX_CLOCK_MASK10x400x000x080x000x000x000x000x00((48000000/9600)-5000)*32=0RX時鐘屏蔽寄存器的波特率RX_CLOCK_MASK00x400x000x090x000x000x000x000x00((48000000/9600)-5000)*32=0
RX_CLOCK_MASK10x400x000x0A0x000x000x000x000x00((48000000/9600)-5000)*32=0[7]:停止位選擇;[6:4]:奇偶校驗?zāi)J竭x擇;[3:0]:數(shù)據(jù)位CHARACTER_FORMAT0x400x000x0B0x000x080x000x000x00停止位-1,奇偶校驗-無,數(shù)據(jù)位-8,00001000

規(guī)格書就是看下面的內(nèi)容,XR_SET_REG? ?0x04的設(shè)置命令

image.png


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频