title: Check sleep mode in avr
body: <p>Currently I'm playing with the avr microprocessor atmega644p and trying to put it in sleep mode (mode: idle).</p>
  
  <p>To do this: I set the SE bit = 1 and other 3 bits SM0 SM1 and SM2 is 0, then when I call function <code>sleep_cpu()</code>, CPU will be in idle mode.</p>
  
  <p>I use interrupt to execute tasks defined in my code so that if I want to execute it, i have to disable the sleep mode. This mean the function <code>sleep_disable()</code> must be put in the first line in <code>ISR(vector_name)</code> function.</p>
  
  <p>Is my logic correct? </p>
  
  <p>And how can I check whether CPU is in sleep mode or not? I tried to do as below:</p>
  
  <pre><code>if (SM0 == 0 &amp;&amp; SM1 == 0 &amp;&amp; SM2 == 0){
  
     printf("Sleep mode begin");
  }
  </code></pre>
  
  <p>Because I use an interrupt so oviously the if statement would be in the loop in <code>main()</code> function but nothing is printed on putty terminal.</p>
  
  <p>why this happens? I think this happens because the if statement is never executed due to wrong condition</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The position of the if statement is above <code>sleep_cpu()</code> inside the loop in <code>main()</code> function so that the line "Sleep mode begin" should be printed out before the CPU go to sleep mode, but there is still nothing print out on putty terminal</p>