2020-07-09 09:48 AM
my interrupt code needs to make a decision based on a flag, which I stored in a global variable. However, the code wont compile as it doesn't recognise the variable inside the interrupt, but does everywhere else. Is this normal?
If it is normal, is there a general purpose register I can use for this information instead? I can't seem to find it in the reference manual
2020-07-09 11:01 AM
Is the variable defined in the same file as the interrupt service routine (ISR), and before the ISR?
JW
2020-07-09 12:45 PM
volatile
2020-07-09 01:34 PM
say your variable is:
==> main.c ?
volatile uint8_t flag;
... code setting the file
==> Interrupt.c
extern volatile uint8_t flag;
void callback_ISR(void) {
if(flag) // do something
The compiler may not have the declaration of the variable in a specific header file, so try to extern is where needed to see if the visibility is improved
2020-07-09 02:58 PM
>>my interrupt code needs to make a decision based on a flag, which I stored in a global variable. However, the code wont compile as it doesn't recognise the variable inside the interrupt, but does everywhere else. Is this normal?
No, you're doing something abnormal, perhaps an issue of scope, or you having functions/variables in different source files?
As pointed out, best to mark things which can change outside of normal code flow as volatile.
2020-07-11 12:49 AM
Variable scope is C basics and has nothing to do with STM32 particularly. One must be able of figuring this out on their own, otherwise it'll be impossible to develop anything anyway.