I want to disable BOD (Brown-Out Detection) while MCU (ATmega328P) enters sleep mode. Here is my code:
sleep_enable(); MCUCR |= (1<<BODS)|(1<<BODSE); MCUCR &= ~(1<<BODSE); sleep_cpu(); sleep_disable();
in buffer , SMCR ;buffer = r16 ori buffer , (1<<SE) out SMCR , buffer in buffer , MCUCR ori buffer , (1<<BODS)|(1<<BODSE) out MCUCR , buffer in buffer , MCUCR andi buffer , ~(1<<BODSE) out MCUCR , buffer sleep in buffer , SMCR andi buffer , ~(1<<SE) out SMCR , buffer
As I read in datasheet, these codes should work but when I simulate the program, this happens in both:
- SE is set.
- Just BODSE is set. (BODS doesn't change! Why?! )
- BODSE is cleared.
- Entered sleep mode.
Even if I set BODS manually (click on it in I/O window) it is cleared automatically after 3 cycles. While datasheet says if you clear BODSE within 3 cycles after setting both BODS and BODSE, BODS remains set.
Is there any problem in my code? or it is simulator's fault?
Also: Should I clear BODS after MCU waked from sleep?
OH, I forgot this: Happy new year!