Hi Guys,
I am using a Atmega328 for an app. The program has a USART, timer and ADC. I am using the stdout library functions for the printf to send strings to the UART. Here is a skeleton of the program;
//stdout definitions for UART //UART_init function definition //ADC_init function definition //Timer_init function definition //TIMER_ISR //flag = 1 set in TIMER ISR /*************************/ //MAIN //CALL ADC_INIT //CALL TIMER_INIT //CALL UART_INIT while(1) { //post processing of ADC value _delay_ms(100); if(flag == 1) { printf("Hello"); } else { printf("Goodbye"); } }
Ok so when I debug it in single stepping mode, the flow goes like this:
//CALL ADC_INIT //CALL TIMER_INIT //CALL UART_INIT while(1) _delay_ms(100); Goes to printf("Hello") but does not print it printf("Goodbye"); TIMER_ISR flag = 1; printf("Hello");
This is just a dummy program to present the problem.
Question is why does the program flow go straight to the printf "Hello" statement and not go to the if loop for checking the flag value?
The flag variable has been declared volatile and is initialized to zero at the very beginning.
Thanks.