0
\$\begingroup\$

I'm trying to interface UART0 with the my laptop using the ICDI
the code I used is from Mazidi's book :

#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 ? enter image description here

\$\endgroup\$
14
  • 2
    \$\begingroup\$ Not related to your problem, but your delayMs is completely broken and will get optimized away by any half-decent compiler. The loop iterators must be volatile. \$\endgroup\$
    – Lundin
    Aug 11, 2020 at 7:44
  • 2
    \$\begingroup\$ Anyway, start by verifying the baudrate with your scope. If you get strange symbols instead of the expected one, that's very likely the cause. Another classic mistake is missing signal ground. \$\endgroup\$
    – Lundin
    Aug 11, 2020 at 7:46
  • \$\begingroup\$ 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 ? \$\endgroup\$ Aug 11, 2020 at 11:41
  • \$\begingroup\$ What do you mean? If you have different baudrates on sender and receiver side, then that's obviously the problem. You have wrong baudrate divisors in the MCU code perhaps? \$\endgroup\$
    – Lundin
    Aug 11, 2020 at 11:42
  • \$\begingroup\$ 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 it worked \$\endgroup\$ Aug 11, 2020 at 11:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.