用的是CH552T,初始化的时候给了Ep1Buffer全部数据赋值0了。端点1输出8字节 255 255 100 4 0 0 0 0,输入Ep1Buffer前8字节都是0,尝试遍历Ep1Buffer数据也全都是0。不知道问题可能出在哪,先谢谢帮忙的坛友!
上位机函数
//读写方式打开设备,并保存其句柄
hHIDRWHandle = CreateFile(MyDevPathName,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
NULL,
NULL);
if (hHIDRWHandle != INVALID_HANDLE_VALUE)SetWindowText(L"读写访问打开设备成功");
else MessageBox(L"读写访问打开设备失败");
//数据输出 WriteReportBuffer是9个字节
WriteReportBuffer[0] = 0;
WriteReportBuffer[1] = 255;
WriteReportBuffer[2] = 255;
WriteReportBuffer[3] = 100;
WriteReportBuffer[4] = 4;
//调用WriteFile函数发送数据sendLen
Result = WriteFile(hHIDRWHandle, WriteReportBuffer, 9, NULL, NULL);
if (Result) SetWindowText(L"数据发送成功");
else SetWindowText(L"数据发送失败");
USBDeviceInit()函数
void USBDeviceInit()
{
IE_USB = 0;
USB_CTRL = 0x00; //清空USB控制寄存器
USB_CTRL |= bUC_LOW_SPEED;
UDEV_CTRL |= bUD_LOW_SPEED;//选择低速1.5M模式
// USB_CTRL &= ~bUC_LOW_SPEED;
// UDEV_CTRL &= ~bUD_LOW_SPEED;//选择全速12M模式,默认方式
UEP0_DMA = Ep0Buffer; //端点0数据传输地址
UEP1_DMA = Ep1Buffer; //端点1数据传输地址
UEP2_DMA = Ep2Buffer; //端点2数据传输地址
UEP4_1_MOD = ~(bUEP4_RX_EN | bUEP4_TX_EN | bUEP1_RX_EN | bUEP1_BUF_MOD) | bUEP4_TX_EN;//端点1单64字节收发缓冲区,端点0收发
UEP2_3_MOD = UEP2_3_MOD & ~bUEP2_BUF_MOD | bUEP2_TX_EN;
UEP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK; //OUT事务返回ACK,IN事务返回NAK
UEP1_CTRL = bUEP_AUTO_TOG | UEP_T_RES_NAK | UEP_R_RES_ACK; //端点1自动翻转同步标志位,IN事务返回NAK OUT返回ACK
//UEP1_CTRL = bUEP_T_TOG | UEP_T_RES_NAK; //端点1手动翻转同步标志位,IN事务返回NAK
UEP2_CTRL = bUEP_AUTO_TOG | UEP_T_RES_NAK; //端点2自动翻转同步标志位,IN事务返回NAK
USB_DEV_AD = 0x00;
UDEV_CTRL = bUD_PD_DIS; // 禁止DP/DM下拉电阻
USB_CTRL = bUC_DEV_PU_EN | bUC_INT_BUSY | bUC_DMA_EN; // 启动USB设备及DMA,在中断期间中断标志未清除前自动返回NAK
UDEV_CTRL |= bUD_PORT_EN; // 允许USB端口
USB_INT_FG = 0xFF; // 清中断标志
USB_INT_EN = bUIE_SUSPEND | bUIE_TRANSFER | bUIE_BUS_RST;
IE_USB = 1;
}
端点1接受数据
case UIS_TOKEN_OUT | 1: //endpoint 1# 中断端点下传
if(U_TOG_OK) // 不同步的数据包将丢弃
{
//memcpy(HIDbuff, Ep1Buffer, 8);
//eflag = 1;
/*contt = 48;
HIDbuff[0] = Ep1Buffer[contt+0];
HIDbuff[1] = Ep1Buffer[contt + 1];
HIDbuff[2] = Ep1Buffer[contt + 2];
HIDbuff[3] = Ep1Buffer[contt + 3];
HIDbuff[4] = Ep1Buffer[contt + 4];
HIDbuff[5] = Ep1Buffer[contt + 5];
HIDbuff[6] = Ep1Buffer[contt + 6];
HIDbuff[7] = Ep1Buffer[contt + 7];*/
/*for (contt = 0; contt < 64; contt++)
{
if (contt == 63)
{
HIDbuff[0] = 1;
HIDbuff[1] = 2;
}
if (Ep1Buffer[contt] != 0)
{
HIDbuff[0] = contt;
HIDbuff[1] = Ep1Buffer[contt];
}
}*/
//memcpy(Ep1Buffer, HIDbuff, 8); //加载上传数据
LED = 0;//这里的LED是为了方便在逻辑分析仪里找到传输的数据
UEP1_T_LEN = 8; //上传数据长度
UEP1_CTRL = UEP1_CTRL & ~MASK_UEP_T_RES | UEP_T_RES_ACK; //有数据时上传数据并应答ACK
LED = 1;////这里的LED是为了方便在逻辑分析仪里找到传输的数据
}
FLAG = 1;
break;
下面是逻辑分析仪截取的通信数据
|