View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
USB CDC hang |
Posted: Thu Jan 07, 2016 7:26 am |
|
|
I have a PIC18F14K50 with a CDC and works ok until I send data from PC then the Windows application hang up.
The VID/PID is default 2409/000B.
I'm using, at the end of data processing routine.(ProcesarBuffer())
Code: | printf(usb_cdc_putc,"Data received OK"); |
And at the main
Code: |
#ifdef enableUSB
usb_init_cs();
while(usb_attached())
{
usb_task();
if(usb_enumerated())
{
if(usb_cdc_kbhit())
{
XByte=usb_cdc_getc();
if(XByte=='>')
{
UsbByteOffset=0;
NewPacket=True;
}
else if(XByte=='*')
{
ProcesarBuffer();
NewPacket=False;
}
if(NewPacket)
{
UsbRxBuffer[UsbByteOffset++]=XByte;
}
}
}
}
#endif
|
The WHILE is needed to avoid that the main program runs if the device start with the USB attached. _________________ Electric Blue |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Thu Jan 07, 2016 8:10 am |
|
|
You don't exactly give us a lot to work on.
However are you sure your 'Windows application' does not require a line feed to know that the data is finished?. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Thu Jan 07, 2016 8:10 am |
|
|
hmmm...
then the Windows application hang up.
What 'windows application'? How is it configured? What else is running? How does it process the data from PIC?
It seems the 'Windows application' can't process the data from the PIC.
There's probably 20 to 30 'things' on the PC Windows side of USB that can easily cause the Windows application to hang up........
I'd start by using a simple 'terminal program' to see the data going to/from the PIC. Confirm the data is good and in the format you're expecting it to be.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Thu Jan 07, 2016 8:56 am |
|
|
The program is a VB.NET application that I programmed too and I debugging it at same time and hang on the line where the data is write to the serial port.
Code: | SerialPort1.Write(">MP2#" & Map & "*" & vbCrLf)
|
So is not waiting any data/line feed because the program never reach that point.
The printf seems to be OK or should I use fprintf?
I will try to use a COM port terminal, and see what happen.
What other info do you need?
Edit:
The CCS CDC uses CTS/RTS or another COM I/O?
I know its a virtual port, but just to be sure. _________________ Electric Blue |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Thu Jan 07, 2016 3:39 pm |
|
|
For tidy operation, you should use DTR. Then in your CDC code test for this being true. Not 'necessary' at this point, but needed to tidily handle the port getting disconnected. Otherwise if the application crashes the port will be in a hung state, and can't be re-opened without shutting the machine down. |
|
![](templates/subSilver/images/spacer.gif) |
|