handling physical disconnection and reconnection

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
thelorax
Posts: 3
Joined: Thu Mar 12, 2009 6:07 am

handling physical disconnection and reconnection

Post by thelorax » Fri May 01, 2009 4:54 am

I've got a device on a battery, and I've finally managed to wrap my head around most of the custom class api.
Right now I'm trying to find any information on handling a physical disconnection from the usb port of a computer. Is there a way the device can know if it's plugged in? How can the device know when to call usb initialization functions? Is it possible to stop calling usbPoll when the device is not connected?
I was thinking I could trigger an interrupt on connection and disconnection and reinitialize and re-enumerate the device there, just like the samples for when the device is just turning on.
Is there a better way?

Thanks for any pointers,
Chris.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: handling physical disconnection and reconnection

Post by christian » Mon May 04, 2009 9:34 pm

You don't need to re-initialize or re-enumerate. The driver handles this automatically.

There are two ways to detect disconnect:
(1) Add hardware to check for USB power, or
(2) Check for USB frame pulses.

For (2), see e.g. Henrik's USB2LPT:
http://www-user.tu-chemnitz.de/~heha/ba ... -15.htm.en

Please note that the frame pulses will also go away when the host goes to sleep. It may be desired to go into battery mode in this case, or it may not be desired.

Post Reply