We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I am trying to setup UART1 have done the setting for GPIO and UART both. The data which I transmit over UART is coming to UART_DR (I am using Keil and CMSIS core Library to code it and in simulation window I can read the data in UART_DR) but I am not getting anything on UART1 window or serial console in Keil debugger.
Here are my code snippets for configuring GPIO and UART along with main function.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define U1RX (1<<4) #define U1TX (1<<5) #define PORTC (1<<2)
#define TXFF (1<<5) #define RXFE (1<<4) #define UART1EN (1<<0)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void GPIOC_Init() { SYSCTL->RCGCGPIO |= PORTC ; //Enable PORTC GPIOC->AFSEL |= (U1TX | U1RX); // Set Pin Functions to Alternate Functions GPIOC->PCTL = (GPIOC->PCTL & 0xFF00FFFF) + 0x00220000; //Set Alternate Functions to UART1 (PMC5 = 0x0010 and PMC4 = 0x0010) GPIOC->DEN |= (U1TX | U1RX); //Enable Digital functionality to UART Pins (PC4 = 1 and PC5 = 1) GPIOC->AMSEL &= ~(U1TX |U1RX);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void UART_Init() { SYSCTL->RCGCUART = 0x02; // Enable UART1 UART1->CTL |=~UART1EN ; //Disable UART before configuration
UART1->IBRD = 0x08; UART1->FBRD = 0x2C; // Baud Clock is 16MHz and BR = 115200 UART1->LCRH = 0x60; // 8N1, FEN disabled UART1->CC = 0x5; // Select clock source as PIOSC System Clock UART1->CTL |= UART1EN; // Enable UART
////////////////////////////////////////////////////////////////////////////////////////
void UART_Send(uint8_t data) { while((UART1->FR & TXFF)){}; // Wait till TX FIFO is Full
UART1->DR = data; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() { uint8_t data[] = {"TM4C123GH6PM UART TX DEMO"}; uint8_t i, ch;
GPIOC_Init(); UART_Init();
for (i = 0; data[i] != '\0'; i++) UART_Send(data[i]);
while(1); }
I also have disabled clock setup in system_TM4C123.c file which is being used at startup. So after doing all this I am not understanding why m I not getting data on console while I get it in UART_DR?
Real hardware? http://www.keil.com/dd/chip/6015.htm Do you have any code establishing output to the debug console? via ITM/SWV? Do you have a terminal or VCP connected to the output pin of the UART? I would expect ITM_SendChar() to work in the simulator, based on the chip level support specified the UART not so much.
I tried once only to connect to real hardware and it did not work.Then I thought I should get it working on simulator then try on real hardware. I also forgot to mention that I am disabling clock settings in system_TM4C123.c file by setting "#define CLOCK_SETUP 0". I hope this might not have huge impact.
I had to do this as the control was not coming out of " while ((SYSCTL->RIS & (1UL<<6)) != (1UL<<6));" statement which checks if PLL is locked or not. I understood from this is that PLL was not getting locked.