Problems with static and global variables

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.

Parents
  • Am I not allowed to use static and global variables for ISRs?

    There is no such limitation. Global and static variables are OK to use in ISRs and normal code.
    My guess is you get memory corruption for reasons unrelated to ISR. Could be memory manipulations with erroneously calculated pointers. Or too little memory allocated for stack, and it grows and wipes out variables. Or something else...

Reply
  • Am I not allowed to use static and global variables for ISRs?

    There is no such limitation. Global and static variables are OK to use in ISRs and normal code.
    My guess is you get memory corruption for reasons unrelated to ISR. Could be memory manipulations with erroneously calculated pointers. Or too little memory allocated for stack, and it grows and wipes out variables. Or something else...

Children
More questions in this forum