I am fairly new to the Tiva C series launchpad and the microcontroller arena, in general. I am using TM4C123GXL launchpad, and keil uvision. Have been fairly successful in implementing basic examples like Blinking etc. That means there's nothing wrong with my configuration of the software. I followed a video lecture which used the serial port connected to the USB to change the LED colours as per the input by the user. The serial monitor I used is Hercules and the baud rate is 9600. I checked with a previous program, the system clock is running at 50 MHz. The program is upload without any issue, but when I open the serial port, nothing comes up.
I was going through the debugger, and for some reason it refuses to move on from the line while((UART0->FR & (1<<5)) != 0);
I am attaching the code below
#include <TM4C123.h>
#include <stdlib.h>
#include <string.h>
char readChar(void);
void printChar(char c);
void printString(char *string);
int main(void) {
// char c;
SYSCTL->RCGCUART |=
(1 << 0); // Enabling the UART module with RCGCUART register
// 2. Enable the clock to the appropriate GPIO module via the RCGCGPIO
// register (see page 340).
// To find out which GPIO port to enable, refer to Table 23-5 on page 1351.
SYSCTL->RCGCGPIO |= (1 << 0);
// 3. Set the GPIO AFSEL bits for the appropriate pins (see page 671). To
// determine which GPIOs to configure, see Table 23-4 on page 1344.
GPIOA->AFSEL = (1 << 1) | (1 << 0);
// 4. Configure the GPIO current level and/or slew rate as specified for the
// mode selected (see page 673 and page 681).
// 5. Configure the PMCn fields in the GPIOPCTL register to assign the UART
// signals to the appropriate
// pins (see page 688 and Table 23-5 on page 1351).
GPIOA->PCTL = (1 << 0) | (1 << 4);
GPIOA->DEN = (1 << 0) | (1 << 1);
// Find the Baud Rate Divisor
// for 50 MHz, we have 27.12673611
UART0->CTL &= ~(1 << 0);
// write the interger portion
UART0->IBRD = 325;
UART0->FBRD = 33;
// write the desired serial parameter
UART0->LCRH = (0x3 << 5);
// select the uart config clock
UART0->CC = 0x5;
// reenable UART
UART0->CTL &= (1 << 0) | (1 << 8) | (1 << 9);
// config LED pins
SYSCTL->RCGCGPIO |= (1 << 5); // PORT F
GPIOF->DIR = (1 << 1) | (1 << 2) | (1 << 3); // LEDs as output
GPIOF->DEN = (1 << 1) | (1 << 2) | (1 << 3); // LEDs as Digital
GPIOF->DATA &= ~((1 << 1) | (1 << 2) | (1 << 3)); // Turn off LEDs
// delay(5);
while (1) {
printString("Enter \"r\",\"g\",or \"b\":\n\r");
char c = readChar();
printChar(c);
printString("\n\r");
switch (c) {
case 'r':
GPIOF->DATA = (1 << 1);
break;
case 'b':
GPIOF->DATA = (1 << 2);
break;
case 'g':
GPIOF->DATA = (1 << 3);
break;
default:
GPIOF->DATA &= ~((1 << 1) | (1 << 2) | (1 << 3));
break;
}
}
}
char readChar(void) {
char c;
while ((UART0->FR & (1 << 4)) != 0)
;
c = UART0->DR;
return c;
}
void printChar(char c) {
while ((UART0->FR & (1 << 5)) != 0)
;
UART0->DR = c;
}
void printString(char *string) {
while (*string) {
printChar(*(string++));
}
}