使用STM32串口控制376S當(dāng)USB host,在發(fā)送完數(shù)據(jù)給USB設(shè)備后能正常的收到設(shè)備返回的前64個(gè)字節(jié)數(shù)據(jù),再次啟動(dòng)接收,設(shè)備就返回NAK了,具體的代碼實(shí)現(xiàn)如下:
//設(shè)置重試次數(shù)-不重試,NAK狀態(tài)返回
Write_CH376_Cmd(CMD_SET_RETRY);
Write_CH376_Data(0x25);
Write_CH376_Data(0x00);
endp6_mode = endp7_mode=0x80; ????????????????//DATA0發(fā)送器
sta = 0;
WR_USB_Data(4,(unsigned char *)"001?");????????????//USB host 發(fā)送此命令給USB 設(shè)備,設(shè)備會(huì)返回200個(gè)字節(jié)的數(shù)據(jù)
Toggle_send();
sta = Issue_token(Out_Num,DEF_USB_PID_OUT);
if(sta == USB_INT_SUCCESS)
{
Uart3_Rx = 0;
for(i=0;i<0xFF;i++)
{
sta = 0;
Toggle_recv();
sta = Issue_token(In_Num,DEF_USB_PID_IN);
if(sta == USB_INT_SUCCESS)????????????????????????????????????????//前面兩次可以返回)0X14,之后就之一返回NAK
{
memset(Uart3.RX_BUF,0,BUFF_LEN);????????????????????//Uart3.RX_BUF:串口接收數(shù)據(jù)緩沖區(qū)
Uart3_Rx = 0;????????????????????????????????????????????????????????//Uart3_Rx:串口中斷次數(shù)
Write_CH376_Cmd(CMD_RD_USB_DATA0);
USB_Delay_us(380000);????????????????????????????????????? ? //由于使用的時(shí)串口中斷接收,所以在發(fā)送完命令后????????????????????????????????????????????????????????????????????????????????????????????????????????延時(shí)一段時(shí)間,等待串口接收完設(shè)備DATA0或者DATA1的數(shù)據(jù)。
sta = 0;
}
}
}
void Toggle_recv(void)?
{??
Write_CH376_Cmd(CMD_SET_ENDP6);//向CH375的端點(diǎn)緩沖區(qū)寫入準(zhǔn)備接收的數(shù)據(jù)
Write_CH376_Data(endp6_mode);
endp6_mode^=0x40;
USB_Delay_us(20);
}
uint8_t Issue_token(uint8_t endpnum, uint8_t pid)?
{??
Write_CH376_Cmd(CMD_ISSUE_TOKEN); ????????//向CH375的端點(diǎn)緩沖區(qū)寫入準(zhǔn)備發(fā)送的數(shù)據(jù)
Write_CH376_Data((endpnum<<4)|pid);//高4位目的端點(diǎn)號(hào), 低4位令牌PID
return (Wait_interrupt());
}
該如何修改一下或者哪里有問(wèn)題才能解決此問(wèn)題把設(shè)備返回來(lái)的數(shù)據(jù)正常全部接收下來(lái)?謝謝了。