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 programming

Status
Not open for further replies.

saurabh17g

New Member
I have set up external interrupt for ATmega32 and my program executing external interrupt service routine. The question is during the execution of the routine, if external interrupt hits the pin again, does the routine continues to execute or the routine is stopped and again begun. I am using Codevision AVR for programming.
 
The Interrupt will be continued until the end of the interrupt routine is arrived.
But the newly triggering will set the interrupt flag in the according register.
So the interrupt routine will be executed again immediatly after the end of previous execution - ( After the RETI assembler command ) .
In most compilers the RETI will be insert automaticly, so you can it see only in Assembler code.
Be careful whith the interrupt trigger low-level or high-level.
The interrupt will be startet again and again until the trigger level disappears.

CodeVision generates a .cof File.
When you'll start this with AVR Studio 4 you can simulate the whole source code there.
To simulate an interrupt set the according port in AVR Studio 4.
That will be a very useful tool for debugging and testing a program.
 
Last edited:
It should be noted that this is the typical occurance of C compilers for the AVR architecture, this is not what occurs on an assembly level though. Interrupt events can be written (if desired) to allow nested interrupts to occur. For AVR GCC you just pass the ISR function an ISR_NOBLOCK parameter. I'm not sure what it would for Code Vision but it should be available as well. On an assembly level, if you don't want nested interrupts to be possible the first instruction has to disable global interrupts, an the last one has to enable them.
 
if you don't want nested interrupts to be possible the first instruction has to disable global interrupts, an the last one has to enable them
That isn't necessary.
After a start of an interrupt routine the I flag in the SREG register will be cleared.
So no further interrupts are possible.
The started interrupt routine will be processed until the end of that routine.
Then there will be insert a RETI comand by compiler.
This RETI comand will set the I Flag in SREG again an the next enabled interrupt can be executed.

The setting and clearing of the I Flag in an interrupt routine is a hardware feature of AVR controllers.

When you want to allow! nested interrupts the first comand in the interrupt routine will be:
#asm("SEI");
A CLI comand at the end of the interrupt routine is not necessary.
Nested interrupts are very bug sensitive.
If many interrupts are started at the same time, a stack overflow can occur and delete some data in the RAM.
 
Hmm, guess you're right I must be mis-remembering things, I hate that =P Thanks for the correction.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top