請(qǐng)教一個(gè)問(wèn)題,CH375用于設(shè)備外置固件模式,枚舉時(shí)怎么不產(chǎn)生USB_INT_EP0_IN啊?

幫幫忙吧,我用CH375做U盤馬上就要答辯了,可是我連枚舉都沒完成那? 謝謝了?


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

(1)先前的Setup中斷,數(shù)據(jù)包不是8字節(jié)的問(wèn)題解決沒? (2)USB_INT_EP0_IN是這樣產(chǎn)生的:分析完Setup包,首先把相關(guān)數(shù)據(jù)用WR_USB_DATA3寫入端點(diǎn)0的上傳緩沖區(qū),當(dāng)數(shù)據(jù)被計(jì)算機(jī)取走,才會(huì)產(chǎn)生這個(gè)中斷


另外: 下載CH372EVT.ZIP,,里面有XFRIM文件夾,參考這個(gè)程序就可以了,你也可以先把這個(gè)程序跑起來(lái),然后修改一下描述符,在進(jìn)行一些協(xié)議處理就可以了.


哥們我還是沒找到原因啊,讀出來(lái)的還是0X07,我也不知道是怎么回事都跳好幾天了 能不能是硬件的事啊


把你的程序貼出來(lái)看看.


我用的是atmega64L.8M晶振

#include #include #include #include #include #define uint unsigned int #define uchar unsigned char

#define CH375_CS_PORT PORTD #define CH375_CS_BIT PD2

#define CH375_INT_PIN PIND #define CH375_INT_BIT PD3

#define CH375_WR_PORT PORTD #define CH375_WR_BIT PD4

#define CH375_RD_PORT PORTD #define CH375_RD_BIT PD5

#define CH375_A0_PORT PORTD #define CH375_A0_BIT PD6

#define CH375_DDR DDRA #define CH375_PIN PINA #define CH375_PORT PORTA #define CH375_WR_H CH375_WR_PORT |= 1<#define CH375_WR_L CH375_WR_PORT &= ~(1< #define CH375_RD_H CH375_RD_PORT |= 1<#define CH375_RD_L CH375_RD_PORT &= ~(1< #define CH375_A0_H CH375_A0_PORT |= 1<#define CH375_A0_L CH375_A0_PORT &= ~(1< #define CH375_CS_H CH375_CS_PORT |= 1<#define CH375_CS_L CH375_CS_PORT &= ~(1< #define CH375_INT_ACTIVE (CH375_INT_PIN &= 1< #define CH375_TO_MCU CH375_DDR = 0x00 #define MCU_TO_CH375 CH375_DDR = 0xff

#define CH375_DAT_OUT CH375_PIN #define CH375_DAT_IN CH375_PORT

typedef union _REQUEST_PACK { unsigned char buffer[8]; struct { unsigned char bmReuestType; //標(biāo)準(zhǔn)請(qǐng)求字 unsigned char bRequest; //請(qǐng)求代碼 unsigned int wValue; //特性選擇高 unsigned int wIndx; //索引 unsigned int wLength; //數(shù)據(jù)長(zhǎng)度 }r; } mREQUEST_PACKET, *mpREQUEST_PACKET;

//設(shè)備描述符 unsigned char DevDes[]={ 0x12 //描述符大小 ,0x01 //常數(shù)DEVICE ,0x10 //USB規(guī)范版本信息 ,0x01 ,0x00 //類別碼, ,0x00 //子類別碼 ,0x37 //協(xié)議碼 ,0x08 //端點(diǎn)0的最大信息包大小 ,0x48 //廠商ID ,0x43 ,0x37 //產(chǎn)品ID ,0x55 ,0x00 //設(shè)備版本信息 ,0x01 ,0x00 //索引值 ,0x00 ,0x00 ,0x01 //可能配置的數(shù)目 ,0x00 //無(wú)意義 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; //配置描述符 unsigned char ConDes[]={ //配置描述符 0x09 //描述符大小 , 0x02 //常數(shù)CONFIG , 0x27 //此配置傳回所有數(shù)據(jù)大小 , 0x00 // , 0x01 //接口數(shù) , 0x01 //配置值 , 0x00 //索引 , 0x80 //電源設(shè)置 , 0x40 //需要總線電源 //接口描述符 , 0x09 //描述符大小 , 0x04 //常數(shù)INTERFACE , 0x00 //識(shí)別碼 , 0x00 //代替數(shù)值 , 0x02//0x03 //支持的端點(diǎn)數(shù) , 0x08//0xFF //類別碼 , 0x06//0x80 //子類別碼 , 0x50//0x37 //協(xié)議碼 , 0x00 //索引 //端點(diǎn)描述符 , 0x07 //述符大小 , 0x05 //常數(shù)ENDPOINT , 0x82 //端點(diǎn)數(shù)目及方向 , 0x02 //支持的傳輸類型 , 0x40 //支持的最大信息包大小 , 0x00 , 10//0x00 //幀等待時(shí)間 , 0x07 , 0x05 , 0x02 , 0x02 , 0x40 , 0x00 , 0x00

}; //配置描述符 unsigned char LangDes[]={0x04,0x03,0x09,0x04}; //語(yǔ)言描述符 //unsigned char SerDes[]={0x12,0x03,'C',0,'H',0,'3',0,'7',0,'5',0,'U',0,'S',0,'B',0}; //字符串描述符 unsigned char SerDes[14]= { 14, //該描述符的長(zhǎng)度為14字節(jié) 0x03, //字符串描述符的類型編碼為0x03 0x55, 0x00, //U 0xd8, 0x76, //盤 0x14, 0x20, // 0xf3, 0x77, // 0x6f, 0x66, // 0xcc, 0x53 // };

unsigned char mVarSetupRequest; // ;USB請(qǐng)求碼 unsigned char mVarSetupLength; // ;后續(xù)數(shù)據(jù)長(zhǎng)度 unsigned char * VarSetupDescr; // ;描述符偏移地址

unsigned char VarUsbAddress ; //設(shè)備地址

unsigned char CH375FLAGERR; //錯(cuò)誤標(biāo)志 unsigned char CH375CONFLAG; //配置標(biāo)志

mREQUEST_PACKET request; //CH375寫命令 void CH375_WriteCMD(uint CMD) { //CH375_CS_L(); //使能芯片 MCU_TO_CH375; CH375_A0_H; CH375_DAT_IN = CMD; CH375_WR_L; asm("nop"); //asm("nop"); //asm("nop;"); //asm("nop;"); CH375_WR_H; Delay1us(); }

//CH375寫數(shù)據(jù) void CH375_WriteDAT(uint DAT) { //CH375_CS_L(); MCU_TO_CH375; CH375_A0_L; CH375_DAT_IN = DAT; CH375_WR_L; asm("nop"); //asm("nop"); //asm("nop;"); //asm("nop;"); CH375_WR_H; //asm("nop;"); //asm("nop;"); //asm("nop;"); //asm("nop;"); //asm("nop;"); //asm("nop;");

//_delay_us(1); }

//CH375讀數(shù)據(jù) uint CH375_ReadDAT(void) { uint temp; CH375_TO_MCU; CH375_A0_L; CH375_RD_L; asm("nop"); //asm("nop"); //asm("nop;"); //asm("nop;"); temp = CH375_DAT_OUT; //寫命令 CH375_RD_H; //asm("nop;"); //asm("nop;"); //asm("nop;"); //asm("nop;"); //asm("nop;"); //asm("nop;");

//_delay_us(1); return temp; } /* 延時(shí)2微秒,不精確 */ void Delay1us() { ; }

void Delay2us( ) { unsigned char i; #define DELAY_START_VALUE 1 /* 根據(jù)單片機(jī)的時(shí)鐘選擇初值,20MHz以下為0,30MHz以上為2 */ for ( i=DELAY_START_VALUE; i!=0; i-- ); }

/* 延時(shí)50毫秒,不精確 */ void Delay50ms( ) { unsigned char i, j; for ( i=200; i!=0; i-- ) for ( j=250; j!=0; j-- ); } int USART_putchar(char CH) { while ( !( UCSR0A & (1< UDR0=CH; return 0; }

int USART_getchar(void) { while ( !(UCSR0A & (1< return UDR0; }

void COM_Initial(void) { UBRR0H = 0; UBRR0L =51;//XTAL=8M 波特率=9600 UCSR0B = (1<} void putstring(unsigned char *s)//輸出字符串 { unsigned int i,j=strlen(s); for(i=0;i USART_putchar(*s++); USART_putchar(0x0d); USART_putchar(0x0a); } /* CH375初始化子程序 */ void CH375_Init( ) { uint RD_Data,k; /* 設(shè)置USB工作模式, 必要操作 */ CH375_WriteCMD( CMD_SET_USB_MODE ); CH375_WriteDAT(1); /* 設(shè)置為使用外置固件的USB設(shè)備方式 */ for ( ;; ) { /* 等待操作成功,通常需要等待10uS-20uS */ if ( CH375_ReadDAT( )==CMD_RET_SUCCESS ) { //putstring("mode ok"); break; } else {} //putstring("mode error"); } for( k=100; k!=0; k-- ) {CH375_WriteCMD( CMD_CHECK_EXIST ); /* 測(cè)試CH375是否正常工作 */ CH375_WriteDAT( 0xAA ); /* 寫入測(cè)試數(shù)據(jù) */ RD_Data = CH375_ReadDAT(); if ( RD_Data == 0x55 ) { //putstring("test ok"); break; } else { //putstring("test error"); } } } //*********************************************************

//********************************************************* //端點(diǎn)0數(shù)據(jù)上傳 void mCh375Ep0Up() { uint i,len; //putstring("mCh375Ep0Up"); if(mVarSetupLength) { //長(zhǎng)度不為0傳輸具體長(zhǎng)度的數(shù)據(jù) if(mVarSetupLength<=8) { len=mVarSetupLength; mVarSetupLength=0; } //長(zhǎng)度小于8則按實(shí)際要求的長(zhǎng)度輸出 else { len=8; mVarSetupLength-=8; } //長(zhǎng)度大于8則傳輸8個(gè),切總長(zhǎng)度減8 CH375_WriteCMD(CMD_WR_USB_DATA3); //發(fā)出寫端點(diǎn)0的命令 CH375_WriteDAT(len); //寫入長(zhǎng)度 for(i=0;i!=len;i++) CH375_WriteDAT(request.buffer[i]); //循環(huán)寫入數(shù)據(jù) //putstring("shangchuan"); } else { CH375_WriteCMD(CMD_WR_USB_DATA3); //發(fā)出寫端點(diǎn)0的命令 CH375_WriteDAT(0); //上傳0長(zhǎng)度數(shù)據(jù),這是一個(gè)狀態(tài)階段 } }

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

//復(fù)制描述符以便上傳 void mCh375DesUp(){ unsigned char k; for (k=0; k!=8; k++ ) { request.buffer[k]=*VarSetupDescr; //依次復(fù)制8個(gè)描述符, VarSetupDescr++; } }

/* CH375中斷服務(wù)程序INT3 */ SIGNAL(SIG_INTERRUPT3) //否則用查詢,修改熔絲位去掉103模式,對(duì)引腳設(shè)置成上拉電阻否則進(jìn)中斷就出不來(lái)了 { unsigned char InterruptStatus; unsigned char length, c1, len,i; uint a[16]; //unsigned char *pBuf; //unsigned char mBuf[64]; //putstring("INT"); CH375_WriteCMD(CMD_GET_STATUS); InterruptStatus =CH375_ReadDAT(); switch(InterruptStatus) { // 分析中斷狀態(tài) case USB_INT_EP2_OUT: // 批量端點(diǎn)下傳成功 CH375_WriteCMD(CMD_UNLOCK_USB); // putstring("EP2 IN");


你說(shuō)的七個(gè)字: CH375_WriteCMD(CMD_RD_USB_DATA); length=CH375_ReadDAT(); for(len=0;len!=length;len++)request.buffer[len]=CH375_ReadDAT(); // 取出數(shù)據(jù) 是指length=7個(gè)? 另外你先不用著急去修改描述符,描述符號(hào)已經(jīng)被你修改錯(cuò)誤了.


我說(shuō)的是length=0x07,而應(yīng)該是等于0x08才對(duì)吧,要不if(length==0x08)這個(gè)語(yǔ)句進(jìn)不去啊


是需要你確認(rèn)length到底是多少,先前你不是說(shuō)是7么?


讀出來(lái)的第一個(gè)數(shù)據(jù)即長(zhǎng)度就是7


不好意思說(shuō)錯(cuò)了,我說(shuō)的是長(zhǎng)度,不是讀出來(lái)的數(shù)據(jù)


if(length==0x08)到底進(jìn)去了沒有,如果您提供的信息是錯(cuò)誤的,甚至不可能產(chǎn)生的現(xiàn)象,我們分析不出來(lái)具體的問(wèn)題出在那里


確實(shí)沒進(jìn)去,讀出來(lái)的長(zhǎng)度等于0x07,把if(length==0x08)改成if(length==0x07)就進(jìn)去了 能不能是我的芯片有問(wèn)題啊


(1)這個(gè)現(xiàn)象很奇怪,按USB協(xié)議規(guī)定,是不可能產(chǎn)生的,把三個(gè)讀寫子函數(shù)調(diào)整一下試試 void CH375_WriteCMD(uint CMD) { CH375_DAT_IN = CMD; MCU_TO_CH375; CH375_A0_H; CH375_WR_L; asm("nop"); asm("nop"); CH375_WR_H; CH375_A0_L; _delay_us( 1 ); }

//CH375寫數(shù)據(jù) void CH375_WriteDAT(uint DAT) { CH375_DAT_IN = DAT; MCU_TO_CH375; CH375_A0_L; CH375_WR_L; asm("nop"); asm("nop"); CH375_WR_H; _delay_us( 1 ); }

//CH375讀數(shù)據(jù) uint CH375_ReadDAT(void) { uint temp;

CH375_TO_MCU; CH375_A0_L; CH375_RD_L; asm("nop"); asm("nop"); temp = CH375_DAT_OUT; //寫命令 CH375_RD_H; _delay_us(1); return temp; } (2)在length=CH375_ReadDAT()后把length用串口打印出來(lái) 還是不行的話,就換個(gè)芯片試試吧


哥們我調(diào)整一下子函數(shù)以后下MCU里就好使了 真是太感謝了,說(shuō)真的你們的服務(wù)真是太到位了 你們辛苦了!!


哥們,能留一個(gè)聯(lián)系方式嗎?更你一樣的境遇。。。


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

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