View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
USB HID cable unplugged detection |
Posted: Fri Apr 08, 2016 12:26 am |
|
|
Greetings! I'm using 18F25K50 and USB HID library. Till now I'm using usb_enumerated() to detect a connection. It seems it doesn't work when I'm trying to determine if the another node is still connected. How can I achieve this?
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Fri Apr 08, 2016 4:23 am |
|
|
Another node?.
The function to detect whether a cable is attached, is usb_attached. This _requires_ you to make a connection to the supply from the USB cable, which is reduced by a resistive divider and fed in to a pin on your PIC. You specify before loading the USB library what this pin is.
You #define USB_CON_SENSE_PIN to the pin required, before loading usb.c
Technically USB actually requires this, unless you are operating off power from the USB bus. This unfortunately is not made clear. The reason it is optional, is because a lot of PIC designs do use usb power.....
If the pin is defined, then usb_enumerated will automatically return false if the cable is not attached. |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Sat Apr 09, 2016 7:11 am |
|
|
Hi! I have a problem! I'm not supplying the pcb through USB so I've left USB Vcc unconnected! Is there other way to detect if there is anything on the USB port? PIC18F25K50 doesn't have sense pin!
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Sat Apr 09, 2016 7:57 am |
|
|
A USB sense connection, is _required_ by USB.....
A lot of people omit this, and then will have problems. You will find your system will get completely screwed, if the USB goes to sleep.
It is only not required, if the system is powered off Vusb.
Sorry but this is a 'read the USB paperwork' one. |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Sat Apr 09, 2016 8:10 am |
|
|
I think you didn`t understand me! My system is powered off Vusb. The USB is working fine. This microcontroller doesn`t have usb sense pin! So in this case how can I detect USB unplugged? usb_enumerate() working fine to determine if there is a USB device attached, but I think it doesn`t detect deattach!
I think I fixed it! I had to send USB close command from the PC and usb_enumerated() changes its state!
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Sat Apr 09, 2016 9:38 am |
|
|
If your unit is powered off Vusb, then if the USB cable is disconnected, your unit will go off. Hence no need for connection sense.... |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Apr 11, 2016 9:36 am |
|
|
Hi,
So, to summarize:
In another thread you asked "what is the best library for 2 way USB communication between the PIC and the PC?" Ttelmah answered "CDC" (or virtual serial port mode). So, you then selected 'HID' mode...... Huh???
Now, you tell us "My system is powered off Vusb." and "I'm not supplying the pcb through USB so I've left USB Vcc unconnected!" That sounds contradictory to me, but perhaps it's just your use of 'non-standard' terminology...???
USB devices are either (1) powered by the USB bus connection, or (2) powered by an external power source. What have you got?
If you have #2, you must have a 'USB sense' connection! This is NOT a special pin on the PIC, but simply a normal digital I/O pin that you pick, and so designate in your code! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
|