AnsweredAssumed Answered

my u8 becomes 0 after leaving the interrupt ?

Question asked by mccarty.michael on Jan 18, 2013
Latest reply on Jan 19, 2013 by K A
I automatically feel stupid asking this question, I feel as if I should know this already. I'm not sure the relation volatile, static and other keywords have with variables that you may access all over the place. 

So if I have a variable that I want to be able to read in one function and in another at what point would I want it to be volatile ? 

This is what I'm doing I have a var that is a simple char rx from the usart, then in my main i read that char and call the function. I debug and see that the char is in fact 'g' in the interrupt but when i get back around to my main its always 0x00

-- defined in some .h file global to everything
volatile static u8 debugChar; // debug char 

-- my int handler, works great ! 
void USARTx_IRQHANDLER(void)
{
  if(USART_GetITStatus(Debug_USART, USART_IT_RXNE) != RESET)
  {
            debugChar = USART_ReceiveData(Debug_USART);
          printf("\n\rDebug input command: %c\n\r",debugChar);
            USART_ClearITPendingBit(USART2,USART_IT_RXNE);
          
  }
}

-- get back to main after leaving int handler and debugChar is 0
          switch(debugChar)
          {
               case 'g':
               testGPIO();
               break;
          }

I have tried just static, i added volatile to it in an attempt to get it to work thinking volatile was a keyword for "things that need to change quickly" but i'm pretty sure thats wrong. 

Thanks for reading this far

Outcomes