cant get attiny45 to wake up

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

ok so it probably a noob mistake but i cant figure it out

 

 

#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/io.h>


int main(void)
{
	
	//// turn on interrupts////
	SREG |= 0b10000000;
	//// turn on int0      ////
	GIMSK |= 0b0100000;
	//// pin set 6 as output /////

    MCUCR &= ~(1<<ISC01);
	MCUCR &= ~(1<<ISC00);
	DDRB = 0b00000010;
	PORTB = 0b00000110;

    /* Replace with your application code */
    while (1) 
    {
		PORTB = 0b00000100;

		sleep_enable();
		sleep_cpu();
		sleep_disable();
		
		PORTB = 0b00000110;
		
		sleep_enable();
		sleep_cpu();
		sleep_disable();

    }
	
	
}
ISR(INT0_vect){
	
}

 

This topic has a solution.
Last Edited: Sat. Apr 14, 2018 - 03:16 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
	GIMSK |= 0b0100000;

Not enough zeros.  Look again:

	GIMSK |= 0b0100000;

So you're setting bit 5, but INT0 is bit 6.

 

Your code is nearly unreadable.  Don't use magic numbers.  Use bit names.  It will at once become much more readable, maintainable, and you'll avoid the problem that got you here in the first place:

#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>


int main(void) {

  GIMSK |= (1<<INT0);
  MCUCR &= ~(3<<ISC00);
  DDRB = (1<<PB1);
  PORTB = (1<<PB2) | (1<<PB1);
  sei();

  while (1) {
    PINB = (1<<PB1);
    sleep_mode();
  }

}


ISR(INT0_vect) {

}

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

thanks is it the not using bit names that was just making it hard to read? 

also i like how you got two bits set so cleanly nice!!!! any way vary much appreciate it! hopefully now i can get the rest of the code working now

MCUCR &= ~(3<<ISC00);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks is it the not using bit names that was just making it hard to read? 

Yup.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]