AVR question

Hello all,

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

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 modes.

Reply to
cw
Loading thread data ...

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

Reply to
Randy Ott

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.

Correct.

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.

Regards,

-=Dave

--
Change is inevitable, progress is not.
Reply to
Dave Hansen

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.