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

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

Hello,

I am trying to execute UART_Echo example code which is given in C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c123gxl\uart_echo and it is working fine(with UART0) . But it does not work when i  change code from UART0 to UART2, here is my code, 

#include "inc/tm4c123gh6pm.h"

#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(UART2_BASE, true);

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

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART2_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART2_BASE,
ROM_UARTCharGetNonBlocking(UART2_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(UART2_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_UART2);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

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

//
// Set GPIO D6 and D7 as UART pins.
//
GPIOPinConfigure(GPIO_PD6_U2RX);
GPIOPinConfigure(GPIO_PD7_U2TX);
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);

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

//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART2);
ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);

//
// Prompt for text to be entered.
//
UARTSend((uint8_t *)"\033[2JEnter text: ", 16);

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

If i short both tx and rx pin, i get some junk data on pUTTY. I tried with UART3 as well but getting samething, can any one please help me where i am doing mistake.

Regards,

Mamatha

  • Hello Mamatha

    Have you Changed startup_ccs.c. For using Interrupt for UART2 you have to provide its Interrupt Declaration in Startup_ccs.c
  • Hello Sanjay,

    Thanks for your reply. I tried changing IntHandler from UART0 to UART2 in all of these startup files.
    DCD UARTIntHandler ; UART2 Rx and Tx
    DCD IntDefaultHandler ; UART0 Rx and Tx
    startup_ccs.c, startup_ewarm.c, startup_gcc.c, startup_rvmdk.S

    But still it is not working.

    Regards,
    Mamatha
  • have you connected your launchpad UART2 pins to your comm software. I mean now your USB cable can not be used for transferring UART data to your COMM software.
  • Hello Sanjay,

    I have not connected my pins to COMM s/w. I thought it works without connection. If you are aware of that, can you please tell me how do i connect those pins to pUTTY software?

    And please let me know whether i can use the same code for all UART(0-7) modules. Because i need to have SDI communication between micro and other device.

    Regards,
    Mamatha
  • you have to use max232 circuit in between your launchpad UART pins to your computer comm Port. Same code can be used for all UART modules with some modification like you did for UART2.
  • Okay

    I have one more question, do i need to change Int Handler in all these files startup_ccs.c, startup_ewarm.c, startup_gcc.c, startup_rvmdk.S or only in startup_gcc.c is sufficeint??

    Thanks and Regards
    Mamatha
  • you need to change only in startup_ccs.c.
  • Ok Thank You for your help.

    Regards,
    Mamatha
  • Hello Mamatha

    You have are going to hit a roadblock after all the to-fro...

    GPIOPinConfigure(GPIO_PD7_U2TX);

    and the next pit stop is going to be

    e2e.ti.com/.../374640

    SIMPLIFIED: UART2 TX pin is a Locked pin for NMI and it needs to be unlocked before configuring it for an other function.

    Regards
    Amit
  • Hi Amit,

    Now i have added 2 lines of code to unlock PD7, here is my code, i have connected TX, RX and GND pin of micro to "USB to Serial converter"   and i am using tera Term VT(Hyper Terminal) to check this code. This setup is working with UART0 and not with UART2 ..

    #include "inc/tm4c123gh6pm.h"
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    int main(void)
    {
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTD_BASE+GPIO_O_CR) |= GPIO_PIN_7;


    GPIOPinConfigure(GPIO_PD6_U2RX);
    GPIOPinConfigure(GPIO_PD7_U2TX);

    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);

    UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    UARTCharPut(UART2_BASE, 'E');
    UARTCharPut(UART2_BASE, 'n');
    UARTCharPut(UART2_BASE, 't');
    UARTCharPut(UART2_BASE, 'e');
    UARTCharPut(UART2_BASE, 'r');
    UARTCharPut(UART2_BASE, ' ');
    UARTCharPut(UART2_BASE, 'T');
    UARTCharPut(UART2_BASE, 'e');
    UARTCharPut(UART2_BASE, 'x');
    UARTCharPut(UART2_BASE, 't');
    UARTCharPut(UART2_BASE, ':');
    UARTCharPut(UART2_BASE, ' ');

    while (1)
    {
    if (UARTCharsAvail(UART2_BASE)) UARTCharPut(UART2_BASE, UARTCharGet(UART2_BASE));
    }
    }

    Can you please check and help me where i am doing mistake.

    Regards,

    Mamatha

  • Hello Mamatha,

    mamatha m said:
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;

    Is the code executing beyond this point when run as it may be in a Hard Fault. Please put a small delay loop of 10 e.g. SysCtlDelay(10).

    Regards

    Amit

  • Hi Amith,

    I tried adding delay still  it is not working, here is my code for uart3. 

    #include "inc/tm4c123gh6pm.h"
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"

    int main(void)
    {

    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlDelay(10);
    //HWREG(GPIO_PORTD_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY;

    //HWREG(GPIO_PORTD_BASE+GPIO_O_CR) |= GPIO_PIN_7;

    GPIOPinConfigure(GPIO_PC6_U3RX);
    GPIOPinConfigure(GPIO_PC7_U3TX);

    SysCtlDelay(10);

    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

    SysCtlDelay(10);

    UARTConfigSetExpClk(UART3_BASE, SysCtlClockGet(),9600 ,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    //while((UART1_FR_R&0x0020) != 0); // wait until TXFF is 0
    SysCtlDelay(10);
    //UART1_DR_R = data;
    UARTCharPut(UART3_BASE, 'E');
    SysCtlDelay(10);
    UARTCharPut(UART3_BASE, 'n');
    SysCtlDelay(10);
    UARTCharPut(UART3_BASE, 't');
    /*UARTCharPut(UART3_BASE, 'e');
    UARTCharPut(UART3_BASE, 'r');
    UARTCharPut(UART3_BASE, ' ');
    UARTCharPut(UART3_BASE, 'T');
    UARTCharPut(UART3_BASE, 'e');
    UARTCharPut(UART3_BASE, 'x');
    UARTCharPut(UART3_BASE, 't');
    UARTCharPut(UART3_BASE, ':');
    UARTCharPut(UART3_BASE, ' ');
    */
    while (1)
    {
    if (UARTCharsAvail(UART3_BASE)) UARTCharPut(UART3_BASE, UARTCharGet(UART3_BASE));
    }
    }

    I am checking UART comm with 2 launchpad (tiva) boards, one to tx and other to rx transmitted data, here also it is not working even though vtg levels are same. Can u plz check it once.

    Regards,

    Mamatha

  • Hello Mamatha,

    If you connect a scope on UTX and URX, what do you see on putting a UARTCharPut.

    Regards
    Amit
  • Hi Amit,

    I don have scope, but i checked tx pin voltage by using multimeter while code is running. Could you plz tell any other easy way to check this Uart operation. 

    I have one more problem with the interrupt. In one of my project i am using both timer0 and timer1 interrupt, if i use these interrupts in the same file it is working fine. If i put those 2 interrupts in different files it is not working.Here, in one file(os_code), inside the 10ms(implemented by timer0) routine i have called the function to enable the timer1 interrupt and have made to interrupt for 5sec and 10sec. Here is my code,

    *********os_code.c**********

    void Task_10ms()
    {
    if(Rx_Complete_Flag == 0x00)
    {
    TIMERUARTINTEnable();
    }
    }

    int main(void)
    {

    Timer0InterruptConfig();
    Timer_UART_Configuration();

    ....

    }

     ************timer1.c***********

     

    void Timer1IntHandler(void)
    {
    // Clear the timer interrupt
    TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    if(Int_Cntrl_Flag == 0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
    Timer1InterruptEnable(10);
    Int_Cntrl_Flag++;
    }
    else
    {
     GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
    Int_Cntrl_Flag = 0x00;
    }
    }


    void Timer1InterruptConfig(void)
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
    TimerConfigure(TIMER1_BASE, TIMER_CFG_ONE_SHOT);
    }

    void Timer1InterruptEnable(unsigned char Time_Delay)
    {
    uint32_t ui32Period;
    ui32Period = ( Time_Delay *(SysCtlClockGet() / 1)) / 1;

    TimerLoadSet(TIMER1_BASE, TIMER_A, ui32Period -1);

    IntEnable(INT_TIMER1A);
    TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    IntMasterEnable();

    TimerEnable(TIMER1_BASE, TIMER_A);
    }

    void Timer_UART_Configuration()
    {
    SysCtlClockSet(SYSCTL_SYSDIV_3|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    Timer1InterruptConfig();

    //UART_Interrupt_Configuration();

    }

    void TIMERUARTINTEnable()
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

    //UART_Int_Enable();
    //digitalWrite(0x01);
    //Rx_Complete_Flag=0x01;
    Timer1InterruptEnable(5);
    while(1);
    }

    If i add both configuration and enabling interrupts in same file i ll get led on after 5 sec and off after 10 sec. But it is not working when put those 2 interrupts in different files within the same project. Can you please check and tell me why it is not working.

    Regards,

    Mamatha

  • Hi Amith,

    UART is working now, problem was with my LaunchPad. None of the Uarts were working in the board.

    Regards,
    Mamatha
  • Hello Mamatha

    What do you mean by "None of the Uarts were working in the board" and how did it work when it was not working?

    Regards
    Amit