AVR question

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello all,

Anyone know if the SLEEP instruction resets the SE bit in the MCUCR

It doesn't say so in the data book, but it'd be logical wouldn't it?

I mean, you come out of the sleep mode and the SE bit is still set, you'd
have to reset it immediately so as not to go into any unintended sleep

Re: AVR question
Quoted text here. Click to load it
No, it does not.  The SE bit only enables sleep mode it does not cause it.
The SLEEP instruction does that.  It is customary to set the SE bit just
prior to executing a SLEEP and reset it after waking up.

Randy Ott

Re: AVR question

Quoted text here. Click to load it

If it doesn't says so, it probably doesn't.  *That's* logical, isn't
it?  ;-)  

MCUCR and the sleep mode bits are model dependent.  For example (just
to grab a couple from the databook on my desk), SE on the AT90S1200 is
MCUCR bit 5, while SE on the AT90S8535 MCUCR is bit 6.

Quoted text here. Click to load it


FWIW, the sleep_mode macro in the sleep.h header included in avr-gcc
sets SE immediately before inserting a sleep instruction, then clears
it immediately following.  

I don't think "unintended sleep modes" is a great danger.  The only
way I could see it happening is if your PC went off to see the wizard
and you started executing data.  If you happen to find a 0x9588 in
your data and the WDT isn't enabled, you might be stuck until reset.

If you're really concerned about it, you might want to clear SE in the
ISR that wakes it rather than waiting until the ISR finishes, but it's
probably not critical.


Change is inevitable, progress is not.

Site Timeline