PLEASE help, the interrupt is not working

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

there are something wrong with the first part of codes."The interrupt service routine (ISR) for ext_int0", interrupt is not working.

Can anyone help me? I use WinAVR compilor,
these codes are for Atmage8,

//interrupt 0, ISR
void EXT_INT0 (void)
{
	PORTB = (1<<PB1); //PB1, LED 

	printf("int-0");
	_delay_ms(1023);
	_delay_ms(1023);
	_delay_ms(1023);
	_delay_ms(1023);
	return ;
}

void interrupt0_init(void)
{
	DDRD = 0xFB;  //PortD.2 is an input, 
	PORTD &= ~0x04;
	
	GICR = 0x40;   //set INT0=1
	
        printf("inable");	
	MCUCR = 0x03;
	asm ("SEI");
}

[/code]

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

Your ISR is not set up properly. The signature should be this:

void ISR(INT0_vect)
   asm ("SEI"); 

just use:

sei();
   _delay_ms(1023); 
   _delay_ms(1023); 
   _delay_ms(1023); 
   _delay_ms(1023); 

Why do you have such a huge delay in an ISR?

Regards,
Steve A.

The Board helps those that help themselves.

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

BTW, to output strings I would always prefer puts() instand of printf().
And I would avoid calling either of these functions from inside an ISR.

/Martin.

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

You should probably start by looking at the following tutorials:

[TUT] Newbie's Guide to AVR Interrupts If you want to use interrupts, start here!
[TUT][SOFT] The traps when using interrupts An excellent introduction to interrupts!

Which you could have found by reading Newbie? Start here!

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

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

thankz guys, i got it working now,