Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

AVR external interrupt 0 problem

Status
Not open for further replies.

saurabh17g

New Member
Please read the program below:
----------------------------------------------------------------------------------------------------------------------------------
#include <mega32.h>

// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
PORTC = 0xaa;

}

// Declare your global variables here

void main(void)
{

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x02;
MCUCSR=0x00;
GIFR=0x40;


// Global enable interrupts
#asm("sei")
DDRC = 0xff;//configuring PORTC as output to test
while (1)
{
// Place your code here

};
}

----------------------------------------------------------------------------------------------------------------------------------

according to the program pasted above, the PORTC pins should give output 0xaa only when INT0 pin gets a falling edge. But in my case, PORTC is enabled forever. I have tried multiple combinations like level triggered , rising edge etc.. but all are giving the same output. Please reply.
 
You did not say if the interrupt is happening unexpectedly or failing to happen. You say the value of PORTC is always the same but do not tell us what that value is.

the PORTC pins should give output 0xaa only when INT0 pin gets a falling edge.
You could add a pin test to clear PORTC so you can see if the problem is startup or ongoing.

But in my case, PORTC is enabled forever.
PORTC should always be enabled forever. But I don't see anything to initialize the value of PORTC.
 
Then you could try initializing PORTC to 00 at the beginning of the program, and perhaps setting it to something else (55?) whenever another pin goes low. (Sort of a software reset.)
 
There is no code anywhere above that sets PORTC to anything but 0xAA after the first interrupt, why do you think it should ever read anything else?; You never set it to anything else. Your code doesn't make PORTC only == 0xAA on a falling edge, it makes it equal 0xAA on the first falling edge, no other code listed does anything else to change this so once set to 0xAA it will stay there.

What specific compiler are you writing this in? Your C calls are very odd, such as the #asm("sei") this is generally included as a function in most C compilers, it equates to the same thing, but you should never explicitly call ASM in a C program like that unless you have good reason. the sei(); function does the same thing, and can be intercepted if need be by other code.
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top