從CH32F103操作CH340代碼移植到CH32V103C8T6,目前可以接受到CH340上傳的數(shù)據(jù),但是數(shù)據(jù)發(fā)送不過去,程序標(biāo)志是顯示發(fā)送成功。
/*發(fā)送數(shù)據(jù)長(zhǎng)度*/ UINT8?TXDUsbCH341BulkOut(?PUINT8?pBuf,UINT8?len?)??//?341批量發(fā)送 { ????UINT8?TxCnt,s,endp?=?ThisUsbDev.GpVar[1]; ????printf("CH341?Out?data:?\r\n"); ????while?(?len?) ????{ ????????Delay_Us(?200?); ????????R8_UH_TX_LEN?=?len?>=?32???32?:?len; ????????for?(?TxCnt?=?0;?TxCnt?!=?R8_UH_TX_LEN;?TxCnt?++?)?{ ????????????TxBuffer[?TxCnt?]?=?*pBuf; ????????????printf("x%02X?",TxBuffer[?TxCnt?]); ????????????pBuf?++; ????????} ????????s?=?USBHostTransact(?USB_PID_OUT?<<?4?|?(endp?&?0x7F),?endp?&?0x80???RB_UH_R_TOG?|?RB_UH_T_TOG?:?0,?0?);??//?OUT數(shù)據(jù) ????????if?(?s?==?ERR_SUCCESS?){ ????????????len?-=?R8_UH_TX_LEN; ????????????endp?^=?0x80;??//?同步標(biāo)志翻轉(zhuǎn) ????????????ThisUsbDev.GpVar[1]?=?endp;??//?保存同步標(biāo)志位 ????????} ????????else ????????{ ????????????return(?s?); ????????????printf("\r\n"); ????????} ????} ????printf("\r\n"); ????return?ERR_SUCCESS; } /*返回?cái)?shù)據(jù)接收長(zhǎng)度,數(shù)據(jù)存放RxBuffer*/ UINT8?RXDUsbCH341BulkIn(?void?)??//?341批量接收 { ????UINT8?i,s,len,endp?=?ThisUsbDev.GpVar[0]; ????//?CH559傳輸事務(wù),獲取數(shù)據(jù),NAK不重試 ????s?=?USBHostTransact(?USB_PID_IN?<<?4?|?(endp?&?0x7F),?endp?&?0x80???RB_UH_R_TOG?|?RB_UH_T_TOG?:?0,?0?); ????if?(?s?==?ERR_SUCCESS?) ????{ ????????endp?^=?0x80;??//?同步標(biāo)志翻轉(zhuǎn) ????????ThisUsbDev.GpVar[0]?=?endp;??//?保存同步標(biāo)志位 ????????len?=?R8_USB_RX_LEN;??//?接收到的數(shù)據(jù)長(zhǎng)度 ????????if?(?len?) ????????{ ????????????printf("CH341?In?data:?\r\n"); ????????????for?(?i?=?0;?i?<?len;?i?++?) ????????????????printf("x%02X?",(UINT16)(RxBuffer[i])?); ????????????printf("\r\n"); ????????} ????????return?len; ????} ????else?if?(?s?!=?(?USB_PID_NAK?|?ERR_USB_TRANSFER?)?) ????????printf("CH341?error?%02x\r\n",(UINT16)s);//?可能是斷開了 ????return?0; }
熱門產(chǎn)品 :
CH32L103: 32位PDUSB低功耗單片機(jī)