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.

UART TM4C123GH6PM

Hello,

#include <stdint.h>

#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "utils/ustdlib.h"

#ifdef DEBUG

void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

void
ConfigureUART(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);

GPIOPinConfigure(GPIO_PC4_U4RX);
GPIOPinConfigure(GPIO_PC5_U4TX);
GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_0 | GPIO_PIN_1);

UARTClockSourceSet(UART4_BASE, UART_CLOCK_PIOSC);

UARTStdioConfig(0, 115200, 16000000);
}

int
main(void)
{

FPULazyStackingEnable();

SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

ConfigureUART();

UARTprintf("Hello, world!\n");

while(1)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

SysCtlDelay(SysCtlClockGet() / 10 / 3);

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

SysCtlDelay(SysCtlClockGet() / 10 / 3);
}
}

above programme not showing "Hello, world! output on terminal. I tried by changing the UART pins. its not showing the output.

can anyone tell me why this is happening. this code is from the example floder in tm4cgxl.

  • Hello Aashish

    How is the UART4 connected to the PC Terminal?

    Regards
    Amit
  • I have connected PC4 (Rx) & PC5 (Tx) pins of UART module 4.

    these pins i connect to the serial to usb converter.

  • Hello Aashish

    Thanks for the explanation. A relook on the code showed that the configuration in the following line is for PC0 and PC1 and not PC4 and PC5

    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    Regards
    Amit
  • Hello Amit
    still its not working. bcz I used UART1 on the portB as PB0(Rx) & PB1 (Tx). I cant see the output on the terminal. but when I used PA0 & PA1 connected to the usb connector present at debugging side then I can see the "HEllO WORLD" output. but when I use another UART using USB to Serial converter printf, UARTPrintf functions not working. only UARTCharPut function work on USB to Serial converter.

    Thanks for answering my each question...
  • Hello Aashish,

    UARTprintf is limited to UART0 to UART2 only. For other UART;s UARTCharPut must be used or uartstdio.c modified to handle the other UART's

    Regards
    Amit
  • Hello Amit,

    As your above reply I already checked that uartstdio.c file. But the problem is that, I am using UART1 i.e. PB0 & PB1 pins. these pins I connect to my USB to serial converter. also give the 3.3v and GND to USB to serial form the launchpad. then in terminal setting the com port=10, baud rate, start bit=1, stop bit=1, parity=none, flow control=none. same baud rate I set in programme as well as in manage option device manager by right clicking I am checking the properties of connected USB to serial everything is OK. but still I cant see the output.

    Thanks & Regards,
    Ashish
  • Hello Ashish,

    Please share your updated code!

    Regards
    Amit
  • #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"

    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Hello World (hello)</h1>
    //!
    //! A very simple ``hello world'' example. It simply displays ``Hello World!''
    //! on the UART and is a starting point for more complicated applications.
    //!
    //! UART0, connected to the Virtual Serial Port and running at
    //! 115,200, 8-N-1, is used to display messages from this application.
    //
    //*****************************************************************************

    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif

    //*****************************************************************************
    //
    // Configure the UART and its pins. This must be called before UARTprintf().
    //
    //*****************************************************************************
    void
    ConfigureUART(void)
    {
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Enable UART0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

    //
    // Configure GPIO Pins for UART mode.
    //
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Use the internal 16MHz oscillator as the UART clock source.
    //
    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(0, 115200, 16000000);
    }

    //*****************************************************************************
    //
    // Print "Hello World!" to the UART on the evaluation board.
    //
    //*****************************************************************************
    int
    main(void)
    {
    //volatile uint32_t ui32Loop;

    //
    // Enable lazy stacking for interrupt handlers. This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
    SYSCTL_OSC_MAIN);

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Enable the GPIO pins for the LED (PF2 & PF3).
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    //
    // Hello!
    //
    UARTprintf("Hello world!\n");

    //
    // We are finished. Hang around doing nothing.
    //
    while(1)
    {
    //
    // Turn on the BLUE LED.
    //
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

    //
    // Delay for a bit.
    //
    SysCtlDelay(SysCtlClockGet() / 10 / 3);

    //
    // Turn off the BLUE LED.
    //
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

    //
    // Delay for a bit.
    //
    SysCtlDelay(SysCtlClockGet() / 10 / 3);
    }
    }

    Actually I change the port in hello programme available in board example folder. its not working but if i download it as it is means using portA it shows the output Hello, World! but in this case no need to connect usb to serial device same cable we use for debugging that shows the output. but when I am using UART1 or other UART and connect USB to serial device it doesn't work.
  • Hello Aashish

    The UART1 us not mapped in UARTStdioConfig(0, 115200, 16000000); function call. It must be UARTStdioConfig(1, 115200, 16000000);

    Regards
    Amit