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 attached usb enumerated

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



Joined: 24 Jul 2004
Posts: 20

View user's profile Send private message

USB attached usb enumerated
PostPosted: Wed Apr 19, 2006 7:11 pm     Reply with quote

Hello

I have been trying to use usb_attached() to determine if the usb cable is actually connected to the project but it always returns true, even when it is not connected. I have defined the usb connection sense pin(pin_b2), and when I test the value of pin_b2 it changes as it should but usb_attached remains the same.

Below I have include the important lines of code

Code:

#define  USB_CON_SENSE_PIN PIN_B2


These line are executed in a function block and are called from main.

Code:

printf("usb enumeration %u\r\n",usb_enumerated());
printf("usb attached %u\r\n",usb_attached());


These lines are executed in main

Code:

while(1){
printf("port b pin b2 %u\r\n",input(pin_b2));
usb_task();
}



Thanks in advance

David Brown
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 20, 2006 12:37 am     Reply with quote

Look at the generated code for the usb_attach() macro in the .LST file.
See if it's actually testing Pin B2. Since your printf statement works,
and it calls "input(PIN_B2)", it's possible that the macro is not generating
the correct code. The .LST file will show what is happening.
dbrown



Joined: 24 Jul 2004
Posts: 20

View user's profile Send private message

PostPosted: Thu Apr 20, 2006 8:52 am     Reply with quote

Thanks PCM

I made a simple mistake, I placed the define statement for the sense pin in the wrong place, I had placed it after usb_chc.h include statement. I changed the location and it works okay now.
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Sun Nov 21, 2010 11:01 am     Reply with quote

Hi, I have similar problem.

I use USB_CON_SENSE_PIN pin and it's declared as input(PIN_D5).
I've connected the USB's 5V(vbus) through a diode to +5V supply source of PIC and sometimes I'm supplying it with an external power, sometimes directly from usb. I've wired the sense pin before the diode, directly to usb vbus pin(not to PIC's vcc).

When I supply the board with an external +5V, if I'm connecting the usb cable for first time, usb enumerates and I see the "USB" symbol on lcd, and then when I plug out the cable the "USB" is deleted..
When I plug in the cable without resetting the pic after the plugging it out, I cannot see "USB" symbol on lcd again. I just want the board to re-connect, but there is no chance.
Also I'm following it from serial ports windows, it enumerates itself as COM9.

When I reconnect the usb cable, it never recognizes by the PC.

This is my code part:
Code:
void main()
{
   setup_wdt(WDT_ON);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);

   set_tris_a(0b11010011);
   set_tris_b(0b00000111);
   set_tris_c(0b10000000);
   set_tris_d(0b11100000);
   set_tris_e(0b00001000);

   usb_cdc_init();
   usb_init_cs(); // init without waiting to connect
   
//   while(!usb_cdc_connected());  // wait usb enumeration
   enable_interrupts(GLOBAL);

   for(;;)
   {
      restart_wdt();
      usb_task();
     
      if (usb_enumerated() && usb_attached())
      {
         UartMenuTask();
         EETask();
      }

      if(usb_enumerated() && usb_attached()) // draw usb-connected icon
      {
         nokia_gotoxy(67,5); // 84-3*6+1
         printf(nokia_printchar,"USB");
      }
      else
         nokia_erase_y(5);
   }
}


How to solve this issue.

Thanks in advance.
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Mon Nov 22, 2010 5:09 am     Reply with quote

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