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 CCS Technical Support

USB_CDC enum

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



Joined: 03 Feb 2016
Posts: 2
Location: Nevada,USA

View user's profile Send private message

USB_CDC enum
PostPosted: Thu Feb 04, 2016 10:29 am     Reply with quote

Compiler 4.128
PIC18F87J50

This code allows fairly reliable enumerations (USB To UART COM10) upon cable connection, as long as I have the "delay_ms(250)" line in. If I lower the delay or remove this line, I get "Device not Recognized" or "Device won't Start".

Any ideas? Thanks

Code:
void main()
{
   InitSystem();
   //setup_adc_ports(NO_ANALOGS);
   setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   
   // Use usb_init_cs()'connection sense' instead of usb_init()
   usb_init_cs(); //Original
   //usb_cdc_init();//Original
   
   
   do
   {
      if(usb_attached())
      {
         usb_task();
         delay_ms(250);
         if(usb_enumerated())
         {
            OUTPUT_HIGH(LED_PIN);
            if((usb_cdc_carrier.dte_present) && (bEnumeratedFlag == FALSE))
            {
               printf(usb_cdc_putc,"Hello, Universal Controller USB!\n\r");
               printf(usb_cdc_putc,"Enter ASCII command or '?'\n\r");
               bEnumeratedFlag = TRUE;
            }
            UsbReceiveTask();
         }
         else
         {
            OUTPUT_LOW(LED_PIN);
            usb_init_cs();
         }
      }
      else
      {  // The cable has been disconnected
         OUTPUT_LOW(LED_PIN);
         bEnumeratedFlag = FALSE;
         usb_cdc_init(); //clear buffers if disconnected
      }
           
   }while(TRUE);

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Feb 04, 2016 3:30 pm     Reply with quote

The problem is that you keep calling init_cs.

This only needs to be called once.

What is happening, is it sees the cable as attached, but it is not enumerated (yet). Your code then calls init_cs again, which resets the hardware, and prevents enumeration. So it keeps looping round not enumerating.
By adding the delay you give it time to enumerate....
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