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 support@ccsinfo.com

USB cable disconnect detection

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



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

USB cable disconnect detection
PostPosted: Fri Oct 22, 2004 8:32 am     Reply with quote

Hi all,
I am having difficulty in detecting the disconnection of the USB connection between my PIC and PC. I am using a circuit identical to the USB development kit.

I would expect the disconnecting the cable would cause the usb_emumeration check on the PIC to become false ( call
Code:
usb_enumerated()
) but this is not the case!

Usb_enumerated continues to be true even when you pull out the USB cable!

Is there anyway for the PIC to detect that the cable has been disconnected? I would have thought the device would no longer be enumerated when the cable is pulled but the ccs library is pretty complicated and I am having difficulty in following it!

Any advice much appreciated!

P.S. Interestingly when you re-plug the cable calls “usb_enumerated” do return false for a while until the device is re-enumerated!
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Sat Oct 23, 2004 9:22 am     Reply with quote

I’ve dug a little deeper. The USBN9603 doesn’t appear to issue an interrupt on disconnection so the PIC stands no chance in knowing! I’ve searched the datasheet and can’t see a configuration which issues an interrupt on disconnect. In fact I can’t even find a register which contains a simple ‘bit’ to signify if a connection is intact!

I thought of a work around in using, via a couple of resistors, the +5v line on the USB to indicate to the PIC when a PC was connected, bit of a bodge, but it would work OK.

Anyone used the USBN9603 and know how to configure it to interrupt on disconnect? Maybe it’s a USB ‘feature’ because as far as I know the only way the USBN6093 will know it’s been disconnected is the fact the PC is no longer polling it as electrically (I believe) the bus is undetectable when idle?
Ttelmah
Guest







PostPosted: Sat Oct 23, 2004 10:45 am     Reply with quote

Will Reeve wrote:
I’ve dug a little deeper. The USBN9603 doesn’t appear to issue an interrupt on disconnection so the PIC stands no chance in knowing! I’ve searched the datasheet and can’t see a configuration which issues an interrupt on disconnect. In fact I can’t even find a register which contains a simple ‘bit’ to signify if a connection is intact!

I thought of a work around in using, via a couple of resistors, the +5v line on the USB to indicate to the PIC when a PC was connected, bit of a bodge, but it would work OK.

Anyone used the USBN9603 and know how to configure it to interrupt on disconnect? Maybe it’s a USB ‘feature’ because as far as I know the only way the USBN6093 will know it’s been disconnected is the fact the PC is no longer polling it as electrically (I believe) the bus is undetectable when idle?

It's a common problem. USB, in places is c*^p....
Your device can use the 'poll' as you suggest, or check the power (beware, that sometimes the power line can get driven by the USB driver chip, and fail to drop as expected, unless this is diode isolated).

Best Wishes
Guest








PostPosted: Sat Oct 23, 2004 10:53 am     Reply with quote

Do you mean Hardware disconnetion or software ?

The FTDI chip has the PWREN# which goes high during USB suspend and when the cable is removed.
Problem solved.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Oct 23, 2004 11:00 am     Reply with quote

From the datasheet
Quote:
This difference is particularly important for bus-powered operations. In such applications, the voltage provided by the bus
may fall below acceptable levels for the clock generation circuit. When this occurs, a reset must be applied to this circuit to
guarantee proper operation. After a delay of 214 XIN clock cycles, the CLKOUT signal is output. This low voltage detection
is typically accomplished in bus-powered applications using a voltage sensor, such as the LP3470, to appropriately reset
the CPU and other components, including the USBN9604.


Reading this would lead me to believe that the chip will not detect it.
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Tue Oct 26, 2004 3:14 am     Reply with quote

Thanks guys,
It does indeed appear that the ‘correct’ (notice the ‘ so as not to rattle the pro-FTDI camp Smile (notice the smiley as well!)) way to monitor connect and disconnect is indeed with a sense on the 5v USB line. This goes for self powered and bus powered devices.
A good datasheet on techniques is here:

http://www.smsc.com/main/anpdf/an106.pdf

I’ve used a 3pin POR (power on reset) IC I had at hand for a few pence and a couple of resistors to do the job nicely. It has the added bonus of allowing me to only switch on the USBN9603 when I only need to (when the PIC detects a USB cable!). It works very well indeed.

A+ to the forum as usual!

Keep well all,

Will
Guest








PostPosted: Tue Oct 26, 2004 11:58 am     Reply with quote

if that's all you wanted then FDTI has several examples showing how to do...
Guest








PostPosted: Tue Oct 26, 2004 2:04 pm     Reply with quote

Will Reeve wrote:
Thanks guys,
It does indeed appear that the ‘correct’ (notice the ‘ so as not to rattle the pro-FTDI camp Smile (notice the smiley as well!)) way to monitor connect and disconnect is indeed with a sense on the 5v USB line. This goes for self powered and bus powered devices.
A good datasheet on techniques is here:

http://www.smsc.com/main/anpdf/an106.pdf

I’ve used a 3pin POR (power on reset) IC I had at hand for a few pence and a couple of resistors to do the job nicely. It has the added bonus of allowing me to only switch on the USBN9603 when I only need to (when the PIC detects a USB cable!). It works very well indeed.

A+ to the forum as usual!

Keep well all,

Will

That's correct and the FTDI chip has that integrated in it..
So it is also possible to monitor a USB suspend....
Hi Ho if you want to clutter your board with chips...
Very Happy
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Oct 26, 2004 2:38 pm     Reply with quote

Make me a mouse with a FTDI chip Razz
Guest








PostPosted: Tue Oct 26, 2004 9:25 pm     Reply with quote

Mark wrote:
Make me a mouse with a FTDI chip Razz

If all you need is a mouse buy one !

Reinventing the wheel is not fun... I can buy a USB mouse for pennies...
Very Happy
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