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 HID cable unplugged detection

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

USB HID cable unplugged detection
PostPosted: Fri Apr 08, 2016 12:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2016 4:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 09, 2016 7:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 09, 2016 7:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 09, 2016 8:10 am     Reply with quote

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! Smile
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Sat Apr 09, 2016 9:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 11, 2016 9:36 am     Reply with quote

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!
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