以下是我的发送与接收函数,不知道是哪里不对,设备端始终返回NAK。我可以确定的是,设备端如果正常收到数据,是不会发送NAK的。在另外一公司芯片(具体芯片就不说了,免得说我打广告)上能正常通信,CH573不行。
请问,我这是什么问题呢。
uint8_t QueryRecv(uint16_t loop_value)
{
uint8_t s = 0, len = 0;
R8_UH_RX_CTRL = RB_UH_R_TOG | RB_UH_R_AUTO_TOG;
while (loop_value--)
{
s = USBHostTransact((USB_PID_IN << 4) | 0x81, R8_UH_RX_CTRL, 200000/20);
PRINT("IN %02x %d\r\n", s, loop_value);
if (s == 0)
{
len = R8_USB_RX_LEN;
PRINT("RECV>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
printf_byte(pHOST_RX_RAM_Addr, len);
printf_byte_str(pHOST_RX_RAM_Addr, len);
PRINT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
datacallback(pHOST_RX_RAM_Addr, len);
return 0;
}
DelayMs(1);
}
return 1;
}
void QuerySend(uint8_t *buf, uint8_t len, uint8_t flag)
{
uint8_t s = 0, i=0;
memcpy(pHOST_TX_RAM_Addr, buf, len);
R8_UH_TX_LEN = len;
R8_UH_TX_CTRL = RB_UH_T_TOG | RB_UH_T_AUTO_TOG;
s = USBHostTransact((USB_PID_OUT << 4) | 0x01, R8_UH_TX_CTRL, 200000/20);
PRINT("SEND %02x %d==========================\r\n", s, flag);
printf_byte(buf, len);
PRINT("\r\n");
printf_byte_str(buf, len);
PRINT("\r\n");
PRINT("====================================\r\n");
if (s == 0 && flag == 0x01)
{
DelayMs(1);
QueryRecv(1000);
}
}