We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm just starting to learn the ins and outs of the Infineon C167CS-40M and have come across a roadblock in my programming. Any time I try to use global or static variables in my ISR, the data in the variables gets cleared out or corrupted somehow.
Am I not allowed to use static and global variables for ISRs? Is there some initialization code for it I'm missing? Or is there some other way to pass variables to the ISR from the main program and vice versa?
Any help is greatly appreciated.
Are your variables clobbered instantly or just now and then? If clobbered instantly - maybe you have an incorrect memory map so that the compiler places the variables where there are no memory. Basically putting down the coffe cup outside the table.
It's odd... if I define it like this:
static char y = 'r';
It is instantly cleared out. But I can define it afterward and it has the correct value. Like this works:
static char y; y = 'r';
But after they are defined, they get cleared out after 'if' statements; more specifically after 'if' statements that include the variable in the code to be executed but not in the condition statement.
So this statement would corrupt y:
char x = 't'; static char y; y = 'r'; if(x == 'p'){ y = 'i'; }
But this statement would not corrupt y:
static char y; y = 'r'; if(y == 'p'){ y = 'i'; }
And neither would this:
char x = 't'; static char y; y = 'r'; if(y == 'p'){ x = 'i'; }
Nor this:
char x = 't'; static char y; y = 'r'; if(x == 'p'){ x = 'i'; }