??? 09/18/06 19:24 Read: times |
#124511 - Variables within ISR |
This may be a stupid question.
I've got a routine in a project I'm working on where I'm attempting to read a string from the UART. I've got it to where it almost works, but experiences some bugginess. I'm using the method of calling a function that reads a set of characters using the "while (!RI)" method. While it usually works, It sometimes hangs the whole shebang on that line. I'm assuming then, that the next logical step would be to rely on interrupts to read SBUF. In doing so, I would want to use a variable to keep track of the current position within the string in order to write the data to the correct location in an array. My question is, would a variable local to an ISR continue to "exist" after each iteration of the ISR? I know I could use a global variable, but I just found out through a seemingly unexplainable bug that global variables should be avoided unless there is no alternative. The next question is, where do I want to keep the array which will hold the entire received data string? Do I pass each character as an argument to another routine from the UART ISR and initialize the array there? If so, should I do the same thing with that position variable I was talking about? Am I making any sense? I just thought maybe you guys might have some insights to potential pitfalls I should avoid. |