Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,160
Helped
14,392
Reputation
29,048
Reaction score
13,144
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,322
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().
 

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
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?
 

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
Whenever HIDTxHandleBusy(USBInHandle) = 0, means it received data right? But when does HIDTxHandleBusy(USBInHandle) becomes set?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,160
Helped
14,392
Reputation
29,048
Reaction score
13,144
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,322
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?
 

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
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...
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,160
Helped
14,392
Reputation
29,048
Reaction score
13,144
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,322
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?
 

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
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top