I am trying to configure UART0 on TM4C123G launchpad. All of my configuration registers are perfect. They've been written with desired values. But somehow, my busy flag is always 1 after first write in data register. I'm using UART0 module on PA0 and PA1 pins. Initialization code is given below.
void UART_Init(void){
SYSCTL_RCGCUART_R |= 0x01; // activate UART0
SYSCTL_RCGCGPIO_R |= 0x01; // activate port A
while((SYSCTL_PRGPIO_R&0x01) == 0){};
UART0_CTL_R &= ~UART_CTL_UARTEN; // disable UART
UART0_LCRH_R = (UART_LCRH_WLEN_8|UART_LCRH_FEN); // 8 bit word length (no parity bits, one stop bit, FIFOs)
UART0_IBRD_R = 43; // IBRD = int(80,000,000 / (16 * 115,200)) = int(43.40277)
UART0_FBRD_R = 26; // FBRD = int(0.40277 * 64 + 0.5) = 26
UART0_CTL_R |= UART_CTL_UARTEN; // enable UART
GPIO_PORTA_AFSEL_R |= 0x03; // enable alt funct on PA1-0
GPIO_PORTA_DEN_R |= 0x03; // enable digital I/O on PA1-0
// configure PA1-0 as UART
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0xFFFFFF00)+0x00000011;
GPIO_PORTA_AMSEL_R &= ~0x03; // disable analog functionality on PA
}
Configuration registers have following values after running above function:
UART0_IBRD = 0x2B //43
UART0_FBRD = 0x1A //26
UART0_LCRH = 0x70
UART0_CTL = 0x301
Only problematic register is UART0_FR
. It should have a value of 0x90 at all instances except while transmitting data. But even after transmission, its busy bit remains 1 which hinders any transmission.
I'm writing UART0_DATA register as follows:
while((UART0_FR_R&UART_FR_TXFF) != 0); //While transmission FIFO is not full, stay here.
UART0_DR_R = data; // Transmit data to serial.