0

I'm writing a C program to program a microcontroller. In practice, when an interrupt handler occurs I go to execute the following code:

uint8_t call_irq_handler = 0; // variable that is modified by the irq handler
uint8_t call_irq_handler_previous = 0;

static __attribute__((interrupt)) void __irq_handler()
{
    call_irq_handler_previous = call_irq_handler;
    call_irq_handler = call_irq_handler + 1;
}

In main, instead, to wait for the interrupt handler to be executed, I put the following while loop:

while (call_irq_handler == call_irq_handler_previous)
{
    count_cmd_write++;
#if DEBUG
    printf("...i didn't get interrupt handler for cmd_write...\n");
#else
    continue;
#endif
}

If I set DEBUG 1, I have no problem, the code is executed and after a while I exit the while loop. However, if DEBUG 0 then I remain in the while, and therefore the interrupt handler is not taken. Anyone know why this happens?

3
  • 1
    Is call_irq_handler_previous volatile? Commented Oct 16, 2021 at 14:15
  • No, it is not volatile. Commented Oct 16, 2021 at 14:19
  • 1
    Duplicate: electronics.stackexchange.com/questions/409545/… Commented Oct 16, 2021 at 20:04

1 Answer 1

1

I solved the problem by going to insert volatile

 volatile uint8_t call_irq_handler = 0; // variable that is modified by the irq handler
        volatile uint8_t call_irq_handler_previous = 0;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.