Problem using UART0 in TM4C123 Tiva C Launch Pad

moahmedatef

New Member
I'm trying to interface UART0 with the my laptop using the ICDI
the code I used is from Mazidi's book :
C:
#include <stdint.h>
#include "tm4c123gh6pm.h"
void UART0Tx(char c);
void delayMs(int n);
int main(void)
{
SYSCTL->RCGCUART |= 1; /* provide clock to UART0 */
SYSCTL->RCGCGPIO |= 1; /* enable clock to PORTA */
delayMs(20); /* wait for output line to stabilize */
/* UART0 initialization */
UART0->CTL = 0; /* disable UART0 */
UART0->IBRD =  104; /* 16MHz/16=1MHz, 1MHz/104=9600 baud rate */
UART0->FBRD =  11; /* fraction part, see Example 4-4 */
UART0->CC = 0; /* use system clock */
UART0->LCRH = 0x60; /* 8-bit, no parity, 1-stop bit, no FIFO */
UART0->CTL = 0x301; /* enable UART0, TXE, RXE */
/* UART0 TX0 and RX0 use PA0 and PA1. Set them up. */
GPIOA->DEN = 0x03; /* Make PA0 and PA1 as digital */
GPIOA->AFSEL = 0x03; /* Use PA0,PA1 alternate function */
GPIOA->PCTL = 0x11; /* configure PA0 and PA1 for UART */
delayMs(1); /* wait for output line to stabilize */
for(;;)
{
UART0Tx('M');
delayMs(1000) ;

}
}
/* UART0 Transmit */
/* This function waits until the transmit buffer is available then */
/* writes the character in the transmit buffer. It does not wait */
/* for transmission to complete. */
void UART0Tx(char c)
{
while((UART0->FR & 0x20) != 0); /* wait until Tx buffer not full */
UART0->DR = c; /* before giving it another byte */
}
void delayMs(int n)
{
int i = 0 , j = 0 ;
for(i = 0 ; i < n ; i++)
{
for(j = 0 ; j < 3180 ; j++)
{

}
}
}
and there are no problems with the COM port I've set it up in a correct way and I made sure to modify options for target to get 16Mhz clock frequency and to debug using ICDI ( I'm using keil uvision IDE)

and All I get is this symbol

What should I do ?

rjenkinsgb

Well-Known Member
Are you getting a new character each second or so?
Or just those then nothing?

If you are getting new characters at regular intervals, it's most likely a baud rate problem.

moahmedatef

New Member
a new character each second and the baudrate is is the same in both the code and puTTY

rjenkinsgb

Well-Known Member
The small Y character appears to be UTF-8; C3BF

For it to receive more than one character for each one sent, the baud rate must be too slow by some amount, so a zero bit in the sent character is seens as the start of a second character.

Looking at the bit patterns, possibly it's sending at 4800 ? Or it could be some intermediate speed.

moahmedatef

New Member
The small Y character appears to be UTF-8; C3BF

For it to receive more than one character for each one sent, the baud rate must be too slow by some amount, so a zero bit in the sent character is seens as the start of a second character.

Looking at the bit patterns, possibly it's sending at 4800 ? Or it could be some intermediate speed.
• I have changed the baud rate in the virtual terminal installed on my pc to 28800 and the baud rate in the code is still 9600 and the character was transmitted correctly what does that mean ?

• The baud rate in this code is 9600 and I got the divisor using the data sheet and the reference book When the baud rate in the pc terminal was 9600 the transmitted character was not the desired When I changed it in the pc terminal to 28800 and in my code it is still 9600

rjenkinsgb

Well-Known Member
28800 is three times 9600.
That implies the UART clock is 3x faster than expected for the calculations you have used?

What is the main oscillator frequency you are using, vs. the osc frequency of the device in the example code?

moahmedatef

New Member
28800 is three times 9600.
That implies the UART clock is 3x faster than expected for the calculations you have used?

What is the main oscillator frequency you are using, vs. the osc frequency of the device in the example code?
16 MHz external oscillator which is by default the oscillator of the MCU

rjenkinsgb

Well-Known Member
Very strange... I have no idea why!

Try tripling the UART clock divider, from 104 to 312 and see if that gives 9600 baud??

moahmedatef

New Member
Very strange... I have no idea why!

Try tripling the UART clock divider, from 104 to 312 and see if that gives 9600 baud??
Yes
Does this mean I have a clock frequency of 48Mz ?