Detect Suspend Mode

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
AlexDigital
Posts: 1
Joined: Sun Jun 08, 2014 8:57 pm

Detect Suspend Mode

Post by AlexDigital » Sun Jun 08, 2014 9:10 pm

Hi guys,

I have an USB application with the V-USB library and want to detect if the host is in suspend mode.
If it's true, then a LED should turn off. When the host wakes up, the LED should turn on.

In my case, D- is connected to INT0. INT1 is already used by another hardware.

Is there an easy method to do that?

Cheers,
AlexDigital

blargg
Rank 3
Rank 3
Posts: 102
Joined: Thu Nov 14, 2013 10:01 pm

Re: Detect Suspend Mode

Post by blargg » Wed Jun 11, 2014 9:04 am

I've done this in my keyboard converter by putting the CPU to sleep regularly and having it woken by the USB interrupt or a timeout interrupt that fires when the host is suspended and thus doing no USB activity. Something like

Code: Select all

static volatile bool usb_inactive;

ISR(TIMER1_OVF_vect)
{
    usb_inactive = true;
}

void check_inactive()
{
    TCNT1 = -inactive_timeout;
    usb_inactive = false;
    sleep_enable();
    sleep_cpu();
    if ( usb_inactive )
    {
        ...
    }
}


You could use the USB_RESET_HOOK to detect when the host reawakens.

Post Reply