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_echo problem

Other Parts Discussed in Thread: EK-TM4C123GXL, TM4C123GH6PM, MAX232, EK-TM4C1294XL

Hi all,

I am getting a problem when working with uart part.  I was test uart_echo programme but i am not getting any data on uart port and hyper terminal. I was used UART0, 115200, 8bit, 1 stop bit. so please regarding to that. thanking you.

.............................................................................

//*****************************************************************************
//
// uart_echo.c - Example for reading data from and writing data to the UART in
// an interrupt driven fashion.
//
// Copyright (c) 2012-2013 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.0.1.11577 of the EK-TM4C123GXL Firmware Package.
//
//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>UART Echo (uart_echo)</h1>
//!
//! This example application utilizes the UART to echo text. The first UART
//! (connected to the USB debug virtual serial port on the evaluation board)
//! will be configured in 115,200 baud, 8-n-1 mode. All characters received on
//! the UART are transmitted back to the UART.
//
//*****************************************************************************

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

//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART0_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE,
ROM_UARTCharGetNonBlocking(UART0_BASE));

//
// Blink the LED to show a character transfer is occuring.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

//
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
//
SysCtlDelay(SysCtlClockGet() / (1000 * 3));

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

}
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
}
}

//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
//
// 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.
//
ROM_FPUEnable();
ROM_FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

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

//
// Enable the GPIO pins for the LED (PF2).
//
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO A0 and A1 as UART pins.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART0);
ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTFIFOEnable(UART0_BASE);
//
// Prompt for text to be entered.
//
UARTSend((uint8_t *)"\033[2JEnter text: ", 16);

//
// Loop forever echoing data through the UART.
//
while(1)
{
}
}

  • Please could you let me know:

    1. Which board are you running this application on?

    2. Have you successfully run the uart_echo example binaries that are included in the TivaWare release for the board?

    Looking at your code, the only obvious problem I see is that the UARTSend function will throw data away if you try to send more data than can fit in the UART FIFO. Assuming you only send a short string, though, this will be fine.

  • Hi Dave ,

    thanks for your quick response..... 

    1. I am using TM4c123GXL bord(tm4c123gh6pm on chip),

    2. yes, the give uart echo example was complied and load successfully but no data on hyper terminal.

    and please rectify my problem.

  • The TIvaWare package for your board includes binaries for each example application. We have tested these and know that they work. Please could you run one of these (flash it to the board using the LM Flash Programmer tool. You will find the binaries in directories named after each toolchain under examples/boards/ek-tm4c123gxl/uart_echo.) and make sure that it works.

    If it works, then we are looking for something that you have changed in the example source or in the toolchain setup that is causing the problem. If it doesn't work then either your board has a problem or there is something wrong in the configuration of your PC, either in Hyperterminal or with the device drivers for the board.

    A couple of other things to check:

    1. Make sure you are connecting your board to the PC using the Debug USB connector and not the Device USB connector. UART0 is supported via the debug connection.

    2. Does Hyperterminal work with other serial devices attached to your PC?

    3. Make sure your Hyperterminal serial port is configured to operate at 115,200bps, 8 bit data, 1 stop bit, no parity.

    If all these things are fine then you will need to use the debugger to determine whether data is being received by the uart_echo application when you type on the PC. Put a breakpoint in the UART interrupt handler (UARTIntHandler) and, if the debugger stops there, step through it to see what is happening. If the debugger doesn't stop there when you type on Hyperterminal then no data is arriving from the PC and you may need to use a logic analyzer or oscilloscope to look at the UART0RX line to see if there is any signal there.

  • Hi Dave,

    Thanks for your information..I overcome that problem with your reference . Now I am getting a problem to read the Uart data . i.e. I simply send one string to UART1 and then I read that string in WHILE loop. here my problem is ..I was send data with out any  problem but at reading time no data is available. please go through code and suggest me. Thanking you.

    #include <stdbool.h>
    #include <stdint.h>

    #include "inc/hw_ints.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_sysctl.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/timer.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"

    void init_uart(){
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);


    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);


    //UARTEnable(SYSCTL_PERIPH_UART1);
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
    // Set up I/O pins for chosen port
    GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART7_BASE, SysCtlClockGet(), 9600,UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
    //UARTFIFOLevelSet(UART7_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);







    }

    }

    int main(void){

    init_uart();

    int i= 0;
    char name[20] = "hi world\n\r";
    while(name[i] != '\0'){
    SysCtlDelay(100000);
    UARTCharPutNonBlocking(UART1_BASE,name[i]);
    i++;
    SysCtlDelay(100000);
    }


    while (1) {

    while(UARTCharsAvail(UART1_BASE)){

    UARTCharPutNonBlocking(UART1_BASE, UARTCharGetNonBlocking(UART1_BASE));
    SysCtlDelay(10000000);
    }




    }

  • Please let me ask one of my original questions again. Have you successfully run one of the pre-compiled versions of uart_echo that is included in TivaWare? I am asking about the uart_echo.bin files that we provide, not a version that you have rebuilt yourself. If this works, we can be sure that your PC Hyperterminal is set up correctly and that the virtual COM port is working.

    Looking at your code, I have a few questions:

    1. Why are you configuring both UART1 and UART7?

    2. The main part of the code uses UART1. This is not connected to the USB virtual COM port so you must be using an external circuit to connect this to your PC somehow. Are you sure this circuit is correct and that the voltage levels you are using are correct for whatever serial port connection you are using?

    3. Your initial UARTCharPutNonBlocking() loop will only work if the string you are sending contains less characters than the transmit FIFO depth. To make it work regardless of the string length, use UARTCharPut() instead. This function will wait for space in the FIFO before writing a character.

  • HI Dave,

    1.  I am working on Keil UV4 compiler . I was download the file directly into the launch pad and i am not using LM flash player hear.  in this case virtual COM port was not working. please guide me in this problem.

    and coming to our questions.

    1.  firstly I planed that send data on UART7 th port and then read that data on UART1 . for that i am using 7th port.

    2. yes, i designed external MAX232 circuit  to read the uart1 data .

  • I'm a but confused over exactly what you are now trying to do but, looking at the last code you post, I don't see any calls to GPIOPinConfigure for the UART7 pins you intend using. Make sure you add these and see if that helps.

    If you are using UART1 and UART7, the virtual COM port our virtual COM port driver will not be involved. Only COM0 is wired to the debug interface which supports the PC virtual COM port. If you are using some other UART, you will either have to modify your LauchPad to connect that UART to the debug interface (and break the connections to UART0) or use some other serial port on your PC (or a USB serial adapter and your MAX232 board). Note, also, that the UART pins on the TM4C232 part are 3.3V pins.

    Have you made sure that your MAX232 circuit is working correctly? Use an oscilloscope to check that characters sent from UART7 appear on the relevant input and output pins of the MAX232 and also make sure that characters sent from the PC are also correctly handled. Are the serial RX signals correct at the TM4C232 pins?

    You originally mentioned that you tried the uart_echo binary from the TivaWare release and that this didn't work for you. That suggests either that you have a problem with the serial port driver on the PC, your Hyperterminal is not configured to talk to the correct COM port, or there is a hardware problem with your LaunchPad. You need to investigate these three and make sure that the hardware and PC-side software is correct.

  • Hi Dave,

    I have a similar problem with the EK-TM4C1294. I searched C:\ti\TivaWare_C_Series-2.1.1.71\examples\boards\ek-tm4c1294xl\uart_echo and C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c1294xl\uart_echo but found no uart_echo.bin. Please advise.

  • Hello Otto

    The bin file is kept in the sub directory of "ccs/Debug", "ewarm/Exe", "gcc" or "rvmdk" based on the IDE

    Regards
    Amit
  • @Otto and (other) "Dave fans"

    Dave - along w/many others - has, "Left the building."

    Interestingly - there had been two, "Dave Wilsons" @ this vendor.   ( that head count now stands @ 1.)

    Vendor's current expert - Amit Ashara - is superb  (and remains, "In the building"...)