I have a question about sei. What happens if an external interrupt occurs before sei has been called?
In my program I do the following:
1 - Enable the interrupt generation in a device connected to my mega16
2 - Enable external INT0 in GIFR (clearing flag), MCUCR and GICR
3 - Start some activity that might trigger the interrupt
4 - call sei and sleep
5 - wake up, call cli immediately
My program works all the times I have tested it. But I still want to make sure that the INT hasn't arrived by the time I call sei. Do AVRs bypass the sleep if the interrupt arrives before sei? Or should I test the INT0 line before calling sei? (Wouldn't like that, as the interrupt might still arrive before sei is executed.)