I want to put an Attiny13 to sleep. In short chapter 7 of the datasheet says you have to do the following:
set sleep mode
sleep enable (set SE bit)
issue SLEEP command

Generally this is done with aid of the 'sleep.h' library and then translates to


If I dont want to use the sleep.h library, the sleep mode and sleep enable are easy to set via 3 bits (SM[1:0] and SE) but how do I issue the SLEEP command? If I look how the sleep.h library actually does it, it is defined as __asm__ __volatile__ ( "sleep" "\n\t" :: ); That seems odd, do i really have to issue the word 'sleep' somewhere in a program to get the attiny to sleep? Cant I just set a register somewhere? The Sleep.h library seems like a lot of overhead if i just want to put a chip to sleep


1 Answer 1


The asm instruction allows the entering of assembly directly; in this case, the AVR has an instruction explicitly for putting the microcontroller to sleep. You can't do this with a register - you have to do it by emitting the relevant assembly instruction.

There's no need to do this yourself, however - sleep.h is not a library, but a header file that's part of avr-libc, and including it and using it will incur no more overhead than doing it yourself; relevant parts will be inlined by the compiler, and any unused parts of the header file will not end up in the compiled result.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.