Hi,
I am currently working on a MCU unit which will respond to external
interrupts in order to perform specific tasks. The controller I am
using: ATmega8A.
The external interrupt is defined as followed:
1 | PORTD |= 0x04; //Activate pull up resistor of PD2
|
1 | GICR |= (1 << INT0); //Enable INT0
|
1 | MCUCR |= (1<<ISC00); //INT0 is executed on every edge
|
The ISR:
1 | /* interrupt code here */
|
1 | v = 1; //sets interrupt variable v to 1
|
The variable v is defined as : volatile int v.
I am currently testing the behavior of the external interrupts. Whenever
an external interrupt is detected a particular code block should be
executed. The interrupt is applied to the INT0 by any logic change.
1 | /* interrupt code here */
|
1 | v = 1; //sets interrupt variable v to 1
|
1 | //int a; //test variable
|
1 | PORTD |= 0x04; //Activate pull up resistor of PD2
|
1 | GICR |= (1 << INT0); //Enable INT0
|
1 | MCUCR |= (1<<ISC00); //INT0 is executed on every edge
|
1 | //TODO:: Please write your application code
|
1 | } while (v == 0); //Wait for interrupt
|
1 | //Communication protocol between MCU unit and GUI software application
|
1 | USART_Transmit(0xFF); //Header start command
|
1 | USART_Transmit(0xFE); //Header finish command
|
1 | } while (v == 0); //Wait for interrupt
|
1 | USART_Transmit(0xFF); //Header start command
|
1 | USART_Transmit(0xFE); //Header finish command
|
[c]
Testing the code, I can say that the interrupts are recognized and the
code is functioning. However, it seems that there is a little bug or
logic error. When the first interrupt occurs (before block 1), block 1
is supposed to be executed. Now, if the second interrupt occurs, the 2nd
block should be executed.
I can see this execution sequence in a pre-written GUI application,
however, most of the time block 1 (when applying the interrupt) is
executed many times after another and than block 2.
It should always be the following sequence: block 1 than block 2 and so
on. I think that this is a timing issue. But I cannot debug this
problem.
I am also wondering if there is a code in C that tells the program to
wait for an external interrupt signal and than continues the program?
Thank you very much in advance.