do i need to use a general purpose register inside an interrupt?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-09 9: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
- Labels:
-
Interrupt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-09 12:45 PM
volatile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-09 1: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-09 2: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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
