CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

USB CDC hang

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

USB CDC hang
PostPosted: Thu Jan 07, 2016 7:26 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Jan 07, 2016 8:10 am     Reply with quote

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



Joined: 01 Jul 2010
Posts: 9102
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 07, 2016 8:10 am     Reply with quote

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
E_Blue



Joined: 13 Apr 2011
Posts: 416

View user's profile Send private message

PostPosted: Thu Jan 07, 2016 8:56 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Jan 07, 2016 3:39 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group