u8?length; u8?i; #define?AUTO #ifndef????AUTO ????//自動(dòng)獲取 ????xWriteCH376Cmd(CMD1H_GET_DESCR);?//0x46 ????xWriteCH376Data(1); ????xEndCH376Cmd(); #else ????//?手動(dòng)傳輸 ????xWriteCH376Cmd(CMD10_WR_USB_DATA7);?//0x2B ????xWriteCH376Data(0x08);?//寫(xiě)入數(shù)據(jù)長(zhǎng)度 ????xWriteCH376Data(0x80);?//?bmRequestType?主機(jī)向設(shè)備發(fā)送 ????xWriteCH376Data(0x06);?//?bRequest?GET_DESCRIPTOR ????xWriteCH376Data(0x00);?//?wValueL? ????xWriteCH376Data(0x01);?//?wValueH ????xWriteCH376Data(0x00);?//?wIndexL ????xWriteCH376Data(0x00);?//?wIndexH ????xWriteCH376Data(0x12);?//?wLengthL ????xWriteCH376Data(0x00);?//?wLengthH ????xWriteCH376Cmd(CMD2H_ISSUE_TKN_X);?//0x4E ????xWriteCH376Data(0x00);?//?同步標(biāo)志 ????xWriteCH376Data(0x0D);?//?發(fā)起控制傳輸 #endif if(Wait376Interrupt()?==?USB_INT_SUCCESS) { ????xWriteCH376Cmd(CMD01_RD_USB_DATA);?//0x28 ????length?=?xReadCH376Data(); ????printf("length?=?%.2x\n",?length); ????for(i=0;?i?<?length;?++i) ????{ ????????printf("%.2x?",?xReadCH376Data()); ????} ????printf("\n"); ????xEndCH376Cmd(); }
使用CMD1H_GET_DESCR指令獲取設(shè)備描述符正確獲取了設(shè)備描述符。
但嘗試使用控制傳輸手動(dòng)獲取時(shí),出現(xiàn)了異常,返回的數(shù)據(jù)長(zhǎng)度為0x7E(十進(jìn)制126),并且可以讀出長(zhǎng)度為0x7E的垃圾數(shù)據(jù)。
根據(jù)手冊(cè),RD_USB_DATA返回的數(shù)據(jù)塊長(zhǎng)度的有效值是0~64。
USART與SPI連接模式都有此問(wèn)題。
什么原因?qū)е马憫?yīng)數(shù)據(jù)異常?請(qǐng)各位大佬解惑。
熱門(mén)產(chǎn)品 :
CH32V317: 互聯(lián)型青稞RISC-V MCU