1

I am trying to understand how to program avr in event-based model, where it reacts to what is going around it.

After reading my chip (ATmega16a) manual and googling I still can't find exact answer to my question.

Both avr-libc manuals I found http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__sleep.html and http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html insist on that it is recommended to enable sleep mode (set SE bit) right before entering sleep and disable it afterwards (by clearing SE). What purpose serves this bit-shuffling? Why can't I just enable sleep mode once at the reset and then freely enter it by just executing 'sleep' instruction where it is needed?

  • 1
    You can. "To avoid the MCU entering the sleep mode unless it is the programmer’s purpose, it is recommended to write the Sleep Enable (SE) bit to one just before the execution of the SLEEP instruction and to clear it immediately after waking up." You can ignore the recommendation if you want. – UncleO Feb 19 '16 at 01:59

1 Answers1

0

You can just enable sleep mode once at the reset and then freely enter sleep.

By clearing the SE bit you can prevent sleeping in situations when you need.