I've exhausted my searches on this forum/example projects/wiki and haven't found anything.
Is there anyway to detect if the host is suspended without using D- as the int0 pin?
My current configuration is:
D- int1
D+ int0
Any tricks available? Can I not use measure frame length? How about USB_COUNT_SOF?
I already have made many boards, most of them are in the field, and many people are requesting a wake if host is sleeping functionality.
Thanks so much Christian, appreciate any help, tips, pointers.
Much Obliged,
Jason
Detecting Suspend Mode
Re: Detecting Suspend Mode
Thanks to Christian again, who helped me offline, I was able to accomplish this.
As Christian described, since I have D- hooked up to int1, toggling on int1 happens every 100ms. So I accomplished detecting sleep with the following code:
sbi is a macro that was depricated but I still like to use so I always include it in my projects as the following:
#define sbi(reg, bit_number) reg |= _BV(bit_number)
#define cbi(reg, bit_number) reg &= ~_BV(bit_number)
I enable my timer2 to the slowest possible setting and turn on overflow.
/* enable timer 2 */
sbi(TCCR2B, CS22);
sbi(TCCR2B, CS20);
sbi(TIMSK2, TOIE2);
I enable interrupts on INT1 with the following:
/* enable Interrupt */
sbi(EIMSK, INTF1);
global static variable:
static int sleeping = 0;
Then the following interrupt handlers.
SIGNAL(SIG_INTERRUPT1)
{
TCNT2 = 0;
sleeping = 0;
}
SIGNAL(SIG_OVERFLOW2)
{
sleeping = 1;
}
just check if sleeping was set.
You should also be very careful as putting anything else in INT1 interrupt handler could slow down the USB scheduler to the point where it breaks.
As Christian described, since I have D- hooked up to int1, toggling on int1 happens every 100ms. So I accomplished detecting sleep with the following code:
sbi is a macro that was depricated but I still like to use so I always include it in my projects as the following:
#define sbi(reg, bit_number) reg |= _BV(bit_number)
#define cbi(reg, bit_number) reg &= ~_BV(bit_number)
I enable my timer2 to the slowest possible setting and turn on overflow.
/* enable timer 2 */
sbi(TCCR2B, CS22);
sbi(TCCR2B, CS20);
sbi(TIMSK2, TOIE2);
I enable interrupts on INT1 with the following:
/* enable Interrupt */
sbi(EIMSK, INTF1);
global static variable:
static int sleeping = 0;
Then the following interrupt handlers.
SIGNAL(SIG_INTERRUPT1)
{
TCNT2 = 0;
sleeping = 0;
}
SIGNAL(SIG_OVERFLOW2)
{
sleeping = 1;
}
just check if sleeping was set.
You should also be very careful as putting anything else in INT1 interrupt handler could slow down the USB scheduler to the point where it breaks.