在做7s64的usb程序,用的是网上的BasicUsb虚拟串口的程序,上位机驱动为atm6124ser.inf,可认出设备,上位机通过串口调试助手可下传数据,下位机将接收到的数据再上传回去,但只能回传一次,就停掉了,在while ( !(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) )处循环,好像是发送未结束,请大家看看是什么问题,都是网上的程序应该没有问题,另外采用atm6124.Inf驱动,不使用虚拟串口,用配套的事例软件读写都没有问题的。
while (1)
{
if (pCDC.IsConfigured(&pCDC))
{
length = pCDC.Read(&pCDC, data, MSG_SIZE);
data[length]=0;
sprintf(message,"Len %d: %s \n\r",length,data);
GUI_PutHZString(0,60,message);
LCD_Refrush(); //刷屏
pCDC.Write(&pCDC, data, length);
}
}
}
//*----------------------------------------------------------------------------
//* \fn AT91F_CDC_Write
//* \brief Send through endpoint 2
//*----------------------------------------------------------------------------
static uint AT91F_UDP_Write(AT91PS_CDC pCdc, const char *pData, uint length)
{
AT91PS_UDP pUdp = pCdc->pUdp;
uint cpt = 0;
// Send the first packet
cpt = MIN(length, AT91C_EP_IN_SIZE);
length -= cpt;
while (cpt--) pUdp->UDP_FDR[AT91C_EP_IN] = *pData++;
pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;
while (length) {
// Fill the second bank
cpt = MIN(length, AT91C_EP_IN_SIZE);
length -= cpt;
while (cpt--) pUdp->UDP_FDR[AT91C_EP_IN] = *pData++;
// Wait for the the first bank to be sent
while ( !(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) )
if ( !AT91F_UDP_IsConfigured(pCdc) ) return length;
pUdp->UDP_CSR[AT91C_EP_IN] &= ~(AT91C_UDP_TXCOMP);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP);
pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;
}
// Wait for the end of transfer
while ( !(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) ) //在此处停住,首次发送没有问题,第二次就停在这里了
if ( !AT91F_UDP_IsConfigured(pCdc) ) return length;
pUdp->UDP_CSR[AT91C_EP_IN] &= ~(AT91C_UDP_TXCOMP);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP);
return length;
} |