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.

UART0 Transmits but doesn't receive

Hello TI,

I m working on LM4f120XL Launchpad tiva board. I am having issue to receive data from UART0. Transmitting is working successfully.

Kindly review my code for mistakes. My code hangs on while(!UARTCharsAvail(UART0_BASE)). Looks like it is not receiving anything or but if my pin configuration is wrong it will not receive too.  We have checked out FTDI uart cable. It receives and transmits fine. Please help me.



#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "driverlib/gpio.h"
#include "inc/hw_nvic.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
//#include "driverlib/flash.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
//#include "driverlib/uart.h"
#include "grlib/grlib.h"
#include "utils/ustdlib.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "driverlib/uart.h"
#include "driverlib/pin_map.h"


int
main(void)
{


    //
    // Enable the PLL and clock the part at 50 MHz.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //Enable peripheral UART0
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); //Enable uart0 peripheral in sleep mode

//to enable green LED on receive complete.
    GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_DIR_MODE_OUT);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);


    // Initialize the UART. Set the baud rate, number of data bits, turn off
    // parity, number of stop bits, and stick mode.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); //Assign pins to UART0
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);

    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 38400,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));
    //
    // Enable the UART.
    //
    UARTEnable(UART0_BASE);
    UARTCharPut(UART0_BASE, 'c'); //send character to make sure tx is working.
    //
    // Check for characters. Spin here until a character is placed
    // into the receive FIFO.
    //
    while(!UARTCharsAvail(UART0_BASE))
    {

    }
   
    //
    // Get the character(s) in the receive FIFO.
    //
    while(UARTCharGetNonBlocking(UART0_BASE))
    {
    }
    //
    // Put a character in the output buffer.
    //
    UARTCharPut(UART0_BASE, 'r');
    //
    // Disable the UART.
    //
    UARTDisable(UART0_BASE);
HWREG(GPIO_PORTF_BASE + GPIO_O_DATA+((GPIO_PIN_3)<<2))=GPIO_PIN_3;
    while(1)
    {
    }
}