USB HID on xmega A3U - how to detect USB is unplugged

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello I have an nice USB HID implementation humming along on an xmega128A3U and realise that I am not getting the UDC_VBUS_EVENT

 

Does anyone have any pointers as to how one might detect when our gadget is unplugged from the PC/how to get the UDC_VBUS_EVENT to fire.

 

FWIW our gadget has USB_CONFIG_ATTR_SELF_POWERED set.

 

Thanks

Ivan Vernot

//realtimedesigns.com.au

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are two ways to detect being unplugged.

 

1. Monitor the +5V from USB. Just pot it down to the MCU's supply voltage and feed it into a normal GPIO. You then have to implement some code to generate the VBUS_EVENTs.

 

2. Enable the USB frame counter and periodically check that it is still incrementing. Be aware that it will overflow. If it doesn't change for 100ms or more, you have been unplugged.