Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Inquiry regarding Interrupts?

Status
Not open for further replies.

ahmed_mahmoud

Junior Member level 1
Joined
Apr 22, 2010
Messages
19
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,416
Chip: ATMEGA32
Compiler= gcc-avr

I wrote a simple code on using external interrupt INT0; however, the chip responds for the first interrupt signal only. In short, I would like to know how can I make the chips respond to each interrupt signal?

Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <avr/sleep.h>

int main(void)
{
	DDRC=0xFF;
        PORTC=0xFF;
		//------------EXTERNAL INTERRUPT
	MCUCSR= 0x00;	
	MCUCR = 0x00; 	//low level interrupt
	GICR |=(1<<INT0);//interrupt mask in GICR
	//GICR = 0xE0; 
	//SREG = 0x80; // Bit7–I: Global Interrupt Enable
	sei(); //enable all interrupts

	set_sleep_mode(SLEEP_MODE_IDLE);
	sleep_mode();
}

ISR(INT0_vect)
{ 
		PORTC=0x00;
    	   }

regards,
Ahmed
 

The interrupt is only disabled while you are inside the interrupt (recursive interrupts are disabled by default).
I don't see a main loop in your code, you have to use at least a while(1); to prevent the execution from exiting the main function;

Alex
 

I tried this one
Code:
while(1) {
set_sleep_mode(SLEEP_MODE_IDLE);
	sleep_mode();
}

However, the interrupt hadn't occurred at all.
 

I have never used the sleep modes so I can't help much but using sleep like this in an endless loop without any condition or delay doesn't seem correct.

Alex
 

ahmed_mahmoud, as alexan_e said, put while(1){} inside main(). Like this

Main(){
.
.
.
.
while(1){
.
.
.
.
Sleep();
} // end while(1) loop
} // end main
NOTE: If you use WDT then Clear WTD bit before go into Sleep mode. Before go into sleep mode, clear necessary interrupt flags and enable all required interrupts. Then only interrupts will be fired when wake-up from the sleep.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top