sleep mode not working in simulator

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not sure what's wrong here, probably something obvious as usual....

When I step through this code in the simulator the Sleep Mode Select register never changes from 0x00 and the Sleep Enable box never checks (bit never sets). If I manually set the SE bit (by clicking on the check box with my mouse during debug) then the simulator goes into sleep mode after the sleep_cpu command as it should. What's going on?

	// put device to sleep until interrupt wakes it up
	for (;;) {
		// set up interrupts
		EIMSK = 0x00; 		// Turn off INT0, INT1 external interrupts
		PCICR = 0x02; 		// Turn on PCIE1 external interrupts (PCINT8-15)
		PCMSK1 = 0x01;		// Enable interrupt on PCINT8
		
		// todo: make sure debug fuse isn't set - it will cause huge current draw
		cli();					// disable interrupts fduring config
		ADCSRA = 0x00;		 	// shut down ADC
		ADMUX = 0x00; 			// shut down internal Vref
		MCUSR &= ~(1<<WDRF);	// need to do this to avoid eternal watchdog loop
		WDTCSR |= (1<<WDCE) | (1<<WDE); // need to do this to avoid eternal watchdog loop
		WDTCSR = 0x00;			// turn off WD (watchdog timer)
		ACSR = 0x00;			// shut down analog comparator
		//sleep_bod_disable();	// disable BOD (brown out detection) during sleep
		

		sleep_enable();			// set the SE (sleep enable) bit todo: why isn't this working?
		SMCR = (1 << SE)|(0<<SM1)|(1<<SM1)|(0<<SM2);			// set the SE (sleep enable) bit
		set_sleep_mode(SLEEP_MODE_PWR_DOWN); // power down is lowest power mode	
		sei();					// enable interrupts
		sleep_cpu();			// go to sleep
		sleep_disable();		// disable sleep after return
	}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess you missed this in the manual?

Simulator Known Issues wrote:
Sleep Modes

The simulator only supports the Idle sleep mode.


Or are you using a modern AVR and sim2?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the reply, that pointed me in the right direction. I had "AVR Simulator" selected as the debug platform and changed it to "AVR Simulator 2". I also had the wrong device selected.

It appears to be working fine now!