Tool/software: Code Composer Studio
What is the best way to access variables inside ISR routines? The timing path is so critical, UART printfs don't work.
Thanks,
Priya
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
What is the best way to access variables inside ISR routines? The timing path is so critical, UART printfs don't work.
Thanks,
Priya
You are correct that formatted print routines are slow and should not be included in interrupt routines. The UARTS have 16 level FIFOs and 16 characters can be quickly stuffed into an empty transmit FIFO without having to wait for any of the characters to be shifted out. If formatting is required, or more characters need to be transmitted, it is best to store a copy of the variables in static variables and set a "transmit" flag. Then format and output the data in your main loop. The main loop can then clear the flag. If the interrupt routine only copies over the static variables if the flag is cleared, you avoid corrupting the data you transmit if another interrupt occurs before the data transmission is complete.
One common mistake made when working with static variables in interrupt service routines is not declaring them as volatile. Without the volatile keyword, the optimizer may not re-read a variable when it already has an old copy of that variable in a register. The problem occurs when that variable (at least the ram version) was updated by an ISR. The main routine may not see the change. The volatile keyword causes the compiler to generate a RAM read or write each time the variable is used or changed.