Trying to find out why my USB always hang after running awhile.

Status
Not open for further replies.

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
hi guys,
Currently using PIC18F25K50 and will use its USB-HID communication to communicate with PC.
But it the USB will always hang after a while. I know this because when my PC send data to it, it does not respond. Below is the part of my main loop coding:

Code:
while(1){
   if((USBGetDeviceState() < CONFIGURED_STATE) ||
      (USBIsDeviceSuspended() == TRUE))
   {
       continue; 
   }
   if(!HIDRxHandleBusy(USBOutHandle))	//Check if data was received from the host.
   {
       ToSendDataBuffer[0] = ReceivedDataBuffer[0];
       USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
   }
}

Anything wrong here?

Is there a possibility that the USB communication has disconnected while the PC is sending data, and causing it to hang?
 

This doesn't look like a complete HID application, e.g. no call to USBDeviceTasks() in the while loop. And there isn't any response generated, no calls to HIDTxPacket().
 

My coding should look like this:

Code:
while(1){

      USBDeviceTasks();

   if((USBGetDeviceState() < CONFIGURED_STATE) ||
      (USBIsDeviceSuspended() == TRUE))
   {
       continue; 
   }
   if(!HIDRxHandleBusy(USBOutHandle))	//Check if data was received from the host.
   {
       ToSendDataBuffer[0] = ReceivedDataBuffer[0];
       USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
       TxFlag = 1;
   }

   if (TxFlag == 1)
   {
     SendDataBuffer[0] = 'A';
     SendDataBuffer[1] = 'B';
     SendDataBuffer[2] = 'C';
			if (HIDTxHandleBusy(USBInHandle) == 0)		 
			{
				USBInHandle = HIDTxPacket(HID_EP, (BYTE*)&SendDataBuffer, HID_INPUT_REPORT_BYTES);
                               TxFlag = 0;

			}
}

Anything wrong with it?

- - - Updated - - -

I found out that maybe it's not the USB hang... I just did not received the data from the PC. But PC shows it sent already... Do you guys have any idea what went wrong?
 

Whenever HIDTxHandleBusy(USBInHandle) = 0, means it received data right? But when does HIDTxHandleBusy(USBInHandle) becomes set?
 

You didn't yet mention that you are asking about Microchip application library USB drivers.

Why don't you review the verbose comments in usb_function_hid.h?
 

You didn't yet mention that you are asking about Microchip application library USB drivers.

Why don't you review the verbose comments in usb_function_hid.h?
Yes... I have reviewed it already... I have used up the function recommended in that file.
Problem is.. Sometimes I can't received any data from the host especially after idle for 10 seconds.. If every 2-5 seconds the host send data, I can receive it. But if idle for 10 seconds, it can't already...
 

My coding should look like this
Should hits the point. In fact we don't know how your exact PIC code or the PC side look like.

I presume that the combination of the PIC HID firmware and Windows HID code provided in the application library will work. Isn't this a good starting point to find out what's wrong in your test?
 

But now my situation is, Sometimes I can't received any data from the host especially after idle for 10 seconds.. If every 2-5 seconds the host send data, I can receive it. But if idle for 10 seconds, it can't already. The host have to retry at least 3 times only can received...
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…