extern "C"

Hello everyone, maybe it's a stupid question but in interrupt handling function I can't rewrite a variable. I'm sure that the interrupt is triggered and assigns a value to var, read_msg function is executed in a loop, but when the value of a variable is checked, it is always equal zero.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  uint8_t var;

extern "C" void USART1_IRQHandler(void)
{
    var = 1;
    if(USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
    {
        if ((USART1->SR & (USART_FLAG_NE|USART_FLAG_FE|USART_FLAG_PE|USART_FLAG_ORE)) == 0) // check for errors
        {
            rx1_buffer[rx1_wr_index++]= (uint8_t) (USART_ReceiveData(USART2)& 0xFF);
            if (rx1_wr_index == RX_BUFFER_SIZE) rx1_wr_index=0;
            if (++rx1_counter == RX_BUFFER_SIZE)
            {
                //rx1_counter=0;
                rx1_buffer_overflow=1;
            }
        }
        else USART_ReceiveData(USART2); // read data even if there is an error
        //DrawChar(100, 100, TFT_BLUE, TFT_BLACK, (const uint8_t*) font8x8, '1', 10);
    }
}



void read_msg()
{
    uint8_t data;
    if(var == 1)
    {
        USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
        data=rx1_buffer[rx1_rd_index++];
        DrawChar(100, 100, TFT_BLUE, TFT_BLACK, (const uint8_t*) font8x8, 'g', 10);
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
    }
}
Last edited on
You need to declare var as volatile uint8_t var;. Otherwise the compiler thinks it doesn't change and optimizes accordingly.
I've tried it before, it also does not work
initialise it first, then you'll know for sure if the ISR was called.
volatile uint8_t var(55)


have you set a breakpoint in the ISR to determine if its really being called?
Last edited on
Topic archived. No new replies allowed.