This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: TM4C123xx UART Stdio

Part Number: TM4C123GH6PM

I am currently working on UART and Timers. UART part is running fine, but when I introduce Timer in the same code UART stops working. What might be the problem?


/* U0Rx receive connected to PA0
U0Tx transmit connected to PA1 */

#include <stdio.h>
#include <stdint.h>
#include "tm4c123gh6pm.h"


void UART_Init(void);
void PortF_Init(void);
void PortE_Init(void);
void Timer_Init(void);


int main(void)
{
volatile unsigned long delay_timer=0;

char c;
PortF_Init();
UART_Init();
PortE_Init();

/* This is timer initialiazation section. Uncommenting any statement stops the working of UART*/

// SYSCTL_RCGC1_R |= 0x00010000; //enable clock to Timer Block 0 (pg 460)
// delay_timer = SYSCTL_RCGC1_R; // Delay for 3-4 clock cycles
// TIMER0_CTL_R = 0x00; // disable Timer0 before initialization (pg 737 )
// TIMER0_CFG_R = 0x00; // 32-bit option (pg 727 )
// TIMER0_TAMR_R = 0x01; // One shot mode and down-counter (pg 729 )
// TIMER0_ICR_R = 0x01; // clear the TimerA timeout flag(pg 754 )


/* UART Section*/

while(1){

while( (UART0_FR_R & 0x00000010) != 0)
{
}

c=UART0_DR_R;
if(c==10)
{
GPIO_PORTF_DATA_R = 0x08;
UART0_DR_R=c;

UART0_FR_R=0x00000080;
while((UART0_FR_R&0x00000008)==1)
{
}

}

if(c==01)
{
GPIO_PORTF_DATA_R = 0x04;

UART0_DR_R=c;
UART0_FR_R=0x00000080;
while((UART0_FR_R&0x00000008)==1)
{
}

}

if(c==00)
{
GPIO_PORTF_DATA_R = 0x00;
UART0_DR_R=c;
UART0_FR_R=0x00000080;
while((UART0_FR_R&0x00000008)==1)
{
}
}
}
}


/* UART_Init*/

void UART_Init(void)
{
SYSCTL_RCGCUART_R |= 0x01; /* activate UART0 */
SYSCTL_RCGC2_R |= 0x01; /* activate port A */

UART0_CTL_R = 0x00000000; /* disable UART */
UART0_IBRD_R = 104; /* IBRD = int(16,000,000 / (16 * 9600)) = int(104.1667) */
UART0_FBRD_R = 11; /* FBRD = round(0.1667 * 64 ) = 11 */

UART0_LCRH_R = 0x70; /* 8 bit word length (no parity bits, one stop bit, FIFOs) */
UART0_CTL_R = 0x0301; /* enable UART, RXE, TXE, LBE */
GPIO_PORTA_AFSEL_R |= 0x03; /* enable alt funct on PA1-0 */
GPIO_PORTA_DEN_R |= 0x03; /* enable digital I/O on PA1-0 */
GPIO_PORTA_PCTL_R = ((GPIO_PORTA_PCTL_R & 0xFFFFFF00)+0x00000011); /* configure PA1-0 as UART */
GPIO_PORTA_AMSEL_R &= ~0x03; /* disable analog functionality on PA */
}

void PortF_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) F clock
delay = SYSCTL_RCGC2_R; // delay
GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock PortF PF0
GPIO_PORTF_CR_R = 0x0E; // allow changes to PF4-0
GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog function
GPIO_PORTF_PCTL_R = 0x00000000; // 4) GPIO clear bit PCTL
GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 input, PF3,PF2,PF1 output
GPIO_PORTF_AFSEL_R = 0x00; // 6) no alternate function
GPIO_PORTF_DEN_R = 0x0E; // 7) enable digital pins PF4-PF0
}

void PortE_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000010; // 1) E clock
delay = SYSCTL_RCGC2_R; // delay
GPIO_PORTE_LOCK_R = 0x4C4F434B; // 2) unlock
GPIO_PORTE_CR_R = 0x06; // allow changes to PE2-1
GPIO_PORTE_AMSEL_R = 0x00; // 3) disable analog function
GPIO_PORTE_PCTL_R = 0x00000000; // 4) GPIO clear bit PCTL
GPIO_PORTE_DIR_R = 0x06; // 5) PE2-1output
GPIO_PORTE_AFSEL_R = 0x00; // 6) no alternate function
GPIO_PORTE_PUR_R = 0x06; // enable pullup resistors
GPIO_PORTE_DEN_R = 0x06; // 7) enable digital pins
}

  • Hi,

               Why don't you use the function given by Tiva WARE library for uart and timer??   Programming registers is difficult task and increase the chance of errors.

    Regards,

    Digvijay

  • One of the primary purposes of TivaWare has been to remove the need for individual users to learn the ins and outs of DRM programming. For this reason, we are not able to offer much support for any questions that only pertain to DRM programming.

    If you want to understand how to program the device with DRM for greater understanding, then the recommendation from TI is to first code the project with TivaWare, and then replace the TivaWare APIs section by section with the DRM code that they execute.

    With that that much said, why are you writing to SYSCTL_RCGC1_R |= 0x00010000 to enable the timer0 clock instead of writing to something like SYSCTL_RCGCTIMER_R?