View previous topic :: View next topic |
Author |
Message |
dbrown
Joined: 24 Jul 2004 Posts: 20
|
USB attached usb enumerated |
Posted: Wed Apr 19, 2006 7:11 pm |
|
|
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
|
|
Posted: Thu Apr 20, 2006 12:37 am |
|
|
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
|
|
Posted: Thu Apr 20, 2006 8:52 am |
|
|
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
|
|
Posted: Sun Nov 21, 2010 11:01 am |
|
|
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
|
|
Posted: Mon Nov 22, 2010 5:09 am |
|
|
any help? |
|
|
|