I have a problem with the UART. I wrote a code and tested it using Putty terminal. The code is just about sending a char from my MCU to the pc, and here is the code:
void UART_INIT(){
SYSCTL->RCGCUART |= (1<<0);
SYSCTL->RCGCGPIO |= (1<<0);
GPIOA->AFSEL = (1<<1)|(1<<0);
GPIOA->PCTL = (1<<0)|(1<<4);
GPIOA->DEN = (1<<0)|(1<<1);
UART0->CTL &= ~(1<<0);
UART0->IBRD = 104;
UART0->FBRD = 11;
UART0->LCRH = (0x3<<5)|(1<<4);
UART0->CC = 0x0;
UART0->CTL = (1<<0)|(1<<8)|(1<<9);
SYSCTL->RCGCGPIO |= (1<<5); // enable clock on PortF
GPIOF->DIR = (1<<1)|(1<<2)|(1<<3); // make LED pins (PF1, PF2, and PF3) outputs
GPIOF->DEN = (1<<1)|(1<<2)|(1<<3); // enable digital function on LED pins
GPIOF->DATA &= ~((1<<1)|(1<<2)|(1<<3)); // turn off leds
}
void printChar(char c)
{
while((UART0->FR & (1<<5)) != 0);
UART0->DR = c;
}
int main(void)
{
UART_INIT();
while(1)
{
printChar('2');
}
}
As it is clear from the code, I am trying to send '2'. When I start the putty terminal, number '2' appears normally, but when I reset the MCU another character appears '&'. If I restarted the MCU again it goes back to '2'. Here is a screenshot for the putty: