Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Tue Oct 11, 2011 1:38 am |
|
|
Any interrupt that is itself enabled - so:
enable_interrupts(INT_RB);
_will_ wake the system from sleep if the interrupt flag gets set, _or_ will prevent the system sleeping, if the interrupt flag is set before you call the sleep instruction.
Basically, before sleeping, you need to turn off _all_ interrupts except the ones that you want to wake the chip. Also, unless you want the wake up interrupt(s) to call a handler, disable_interrupts(GLOBAL);
You also need to clear the interrupts you are going to use, if they may have become set while the chip was awake. All this before sleeping.
Now, after waking, if you don't want handlers to be called for the interrupt(s) that woke you, you need to clear the interrupts, and/or disable them.
Remember that to _clear_ an interrupt (in the case of one triggered by a hardware event), you may also need to clear the hardware event itself - so in the case of INT_RB above, you would need to read PORTB, before clearing the interrupt.
Remember also, that in some cases, failure to handle an interrupt, can leave the hardware in a locked condition. So (for instance), if you left the master clock running, and disabled INT_RDA, while you slept, then woke up, cleared the interrupt, and re-enabled it, you have a very good chance, that the UART will now be in a locked condition. Problem here is that if two characters have arrived, and not been handled, the UART will have overflowed. So here you would have to either use:
Code: |
while (kbhit()) dummy=getc();
|
Then clear and enable the interrupt, or manually turn off CREN, read the buffer and re-enable the UART.
All of these are described in the data sheet, but the number of permutations is almost infinite (dozens of potential interrupt sources, which can be enabled/disabled in any combination, and may be used just to wake, and/or to call handlers). So there is no global 'example that will work all the time'. It'll depend totally on what combinations of interrupts you are using, and what you are actually doing with them....
Best Wishes |
|