Strange UART behavior - RX Interrupt reads garbage
2006-02-27 by Michael Bate
I am using the ATmega168 and the ImageCraft C compiler (version 7.02).
My program does interrupt-driven UART communications (among other
things).
It appears that it the program gets "too big" (even though all sizes
are within allowable limits), that the input (as viewed with the AVR
Studio debugger in the Receive Interrupt routine) becomes garbled.
Examining the UART registers (which control baud rate, data bits,
stop bits, etc.) shows identical values as with a smaller version of
the program, which works correctly.
The problem can be made to go away by removing the following code
from the initialization sequence:
CLKPR = (1<<CLKPCE); // enable clock prescaler
change
CLKPR = 0x00; // set prescaler to
divide-by-1
This code was added by my predecessor and I'm not sure what it
accomplishes, since it seems to be adjusting the clock speed by
dividing by 1 (which should result in no change).
Has anyone seen a problem like this?
Thanks in advance,
Michael Bate