Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:05:51+00:00 2026-05-24T12:05:51+00:00

My program contains few global variables , whose values are set during the interrupt

  • 0

My program contains few global variables , whose values are set during the interrupt service routine (USCI_A0_ISR()) execution.

Once the execution of USCI_A0_ISR() is done , will the global variables hold the value assigned or will be set back to void/0.????

//Global variables
int ptr = 0;
char rxBuffer[16]; 
int flag = -1;
int check[2];

void __set_flag(void)
{

    if (strcmp(rxBuffer,"OK") == 0) flag = 0; 
    else if (strcmp(rxBuffer,"CONNECT") == 0) flag = 1;
    else if (strcmp(rxBuffer,"NO CARRIER") == 0) flag = 3;
    else if (strcmp(rxBuffer,"ERROR") == 0) flag = 4;

}

void __GSM_client(void)
{
    while (flag == -1);
    if (flag == 0) check[0] = buflen(rxBuffer);
}

void main(void)
{
    __Buffer_init();
    __low_level_init();         //WDT 
    __UART0_init();                 //UART 

    __bis_SR_register(GIE);       //interrupts enabled
    __delay_cycles(1000);           // wait till UART intial

    __GSM_client();

    __no_operation();             // For debugger
}

#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
    char byte;
    while (!(UCA0IFG&UCTXIFG));             
    byte=  UCA0RXBUF;
    UCA0TXBUF = byte;
    if (byte == '\r') { 
        //push_char(byte);
        ptr = 0;
        __set_flag();
        //__Buffer_init();              
    }
    else{                       
        push_char(byte);
    }
}

Here is the code snippet of what I am doing. I am setting the "flag" based on the response obtained . When I see the register view in Code Composer Studio , the "flag" value is set correctly , but if try using the value of "flag" elsewhere the value of "flag " is not reflected.

Any pointers over concepts of the interrupt service routine or when loopholes in my coding method appreciated
Thanks in Advance
AK

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:05:51+00:00Added an answer on May 24, 2026 at 12:05 pm

    Within the interrupt, you are directly or indirectly changing several global variables, e.g. ptr, flag, and I’m assuming rxBuffer[?]. They are not declared “volatile” so their value may or may not change when you return from the interrupt. This is a bug because the behavior can change based on where in the execution of the code the interrupt occurs and what the level of optimization is. As a rule of thumb, any variable modified by an interrupt routine should always be declared volatile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand the practical difference during the execution of a program
I'm writing a program that contains a generational garbage collector. There are just two
I've got a list in a Python program that contains a series of numbers,
I have to write a program that read from a file that contains the
I'm implementing IXMLSerializable in one of my classes. It contains a few numeric properties
In my program I have a few structs and a char array that I
The program saves a settings file as text which contains floating point numbers of
I have a file (a few GB), contains the data <doc> <a1>11111</a1> <b1>22222</b1> <c1>33333</c1>
How to do a Perl program that contains an array and that array points
I have a few <div> inside a forms, each thing inside the div contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.