All Interrupts Turn OFF

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

Hi to all!

I'm having some trouble the folowing structure code:

//global
volatile unsigned char myCHAR;

void EMERGENCY(unsigned char myChar)
{
while(1){

//some code here with myChar                

        }

}

TIMER_1_OVF()
{
PORTD.7 = ~PORTD.7 //just to see if the INT is ON
//some code here
}

void main (void)
{
//some code here
}

Well...The question is: Everytime that the function EMERGENCY() is called, ALL interrupts of the ATMEGA88
TURNS OFF! All of them!(timer, ext int, etc)...
I saw this in another situations, like when I use 'while' as a delay inside a function....
BUT if I use 'while' as a delay in the 'main', it goes alright!

Anyway, delay is not my problem, but WHY a 'while(1)' inside my function would cause the INT's to be disabled.

PS: ALL global variables of mine are 'volatile'

Thanks!

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

Look at the generated assembler of EMERGENCY() - is there any sign of a CLI opcode?

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

Are you perhaps calling EMERGENCY() from an interrupt service routine? If so, interrupts will be disabled by default (though there are ways to declare an ISR to reenable interrupts in the prologue of the ISR).

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

Well Well!
You're right kmr! EMERGENCY() was being called from the timer1 ISR! Although I did not saw any 'cli' in the generated assembly, all INT's was turned off !

I put the EMERGENCY() call in another place, and it worked correctly!

I've been burning my brain too much because of that problem!

Thank you very much guys!

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

Quote:

EMERGENCY() was being called from the timer1 ISR! Although I did not saw any 'cli' in the generated assembly, all INT's was turned off !

Check your datasheet for something like this!
Quote:
When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The user software can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a Return from Interrupt instruction – RETI – is executed.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Cool, Jaguar, I'm glad that you got it sorted out.