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.

TIVAC tm4c123gh6pm UART problem



hello,  

In my project i want to use UART 2 to communicate with zigbee. I have written code to activate UART2 but i didn't seen my data in that UART2_BASE register using putty terminal.but it works for  UART0 so,what the problem with other UARTs

my code is

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

#define GPIO_PC4_U4RX 0x00021001
#define GPIO_PC5_U4TX 0x00021401

#define GPIO_PD6_U2RX 0x00031801
#define GPIO_PD7_U2TX 0x00031C01

int main(void) {

SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

GPIOPinConfigure(GPIO_PD6_U2RX);
GPIOPinConfigure(GPIO_PD7_U2TX);
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6| GPIO_PIN_7);

UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 115200,
(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));
}

}

so please suggest me how can i overcome this problem

  • Hello Karthik

    Please read the documentation. PD7 is a locked pin and needs an unlock sequence

    e2e.ti.com/.../374640

    Regards
    Amit
  • amit,
    i have unlocked that pins by adding that lines and also
    in startup.ccc i have added my function for uart 2.still the data is not absorved in putty terminal.
    the code is


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

    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_memmap.h"

    void UARTIntHandler(void)
    {
    uint32_t ui32Status;

    ui32Status = UARTIntStatus(UART2_BASE, true); //get interrupt status

    UARTIntClear(UART2_BASE, ui32Status); //clear the asserted interrupts

    while(UARTCharsAvail(UART2_BASE)) //loop while there are chars
    {
    UARTCharPutNonBlocking(UART2_BASE, UARTCharGetNonBlocking(UART2_BASE)); //echo character
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
    SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
    }
    }

    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);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //enable GPIO port for LED
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //enable pin for LED PF2

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

    IntMasterEnable(); //enable processor interrupts
    IntEnable(INT_UART2); //enable the UART interrupt
    UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts

    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) //let interrupt handler do the UART echo function
    {
    // if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
    }

    }


    please tell me what the wrong is.......

    regards
    karthik
  • Hello Karthik

    I ask this question often for UART: How are you connecting UART2 to the PC?

    If you check with a scope do you see any activity on UART TX and are UART TX and RX pins high when in idle state=?

    Regards
    Amit
  • thanks amit,

    i want to transmit first to uart 2 through that Rx and Tx pins which connected to zigbee Tx and Rx i want to transmit that data to another device.
    Tiva c is directly connected to my pc with usb cable.
    when i checked putty i didn't see any thing.
    please tell me how i can solve this issue??

    regards
    karthik
  • Hello Karthik,

    But how is UART2 connected to PC. Is there a USB to UART Dongle that you have?

    Regards
    Amit
  • Amit Ashara said:
    But how is UART2 connected to PC. Is there a USB to UART Dongle that you have?

    I read this as user connecting UART2 directly to his Zigbee device - which (one hopes) provides CMOS/TTL signal levels.   Thus NO USB-UART dongle is required.

    User's use of a terminal program - which (potentially) involves only UART0 - seems questionable...

    Pity that the Launchpad user guide is so loaded w/"booster-pack" push/description - and that basic operation is mentioned most briefly...

  • amit,

    i have confused now.I have only tivac with usb cable .I want use UART 2 as a mediator .it is a software register only ,the information directly goes to that pd6 and pd7 pins . iam in a right way or not????
    please tell me

    regards
    karthik
  • amit,

    kentec display board is already used uart 0 thats why i want to use uart 2 for my zigbee.
    thats why i using uart2

    regards
    karthik
  • Hello Karthik,

    Can you draw on paper what your "current" hardware setup is? And attach it to the forum post. Unfortunately information from you is coming in "pieces".

    Regards
    Amit
  • amit,

    1) i want to connect pd6(rx) pd7(tx) of tiva c to xbee dout and din , tiva c 3.3v ,gnd to xbee 3.3 v ,gnd to enable information from pc to xbee
    2) i have connected tiva c with kentec booster pack for graphical display which is controlled based on information recieved from xbee

    regards
    karthik
  • Hello Karthik

    karthik karanam said:
    1) i want to connect pd6(rx) pd7(tx) of tiva c to xbee dout and din , tiva c 3.3v ,gnd to xbee 3.3 v ,gnd to enable information from pc to xbee

    But how have you connected it now for testing?

    Regards

    Amit

  • thanks amit,
    i understand that, first of all i have to connect zigbee and then i have to recieve information from that pd7 pin .for verification of that only we can use that putty terminal.at first i thought uarts in software registers basis, thats why i got confused.know i understand the problem.
    thanks for ur information.
    can you please check for unlocking pd7 is my code is correct or not????

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

    #define GPIO_PC4_U4RX 0x00021001
    #define GPIO_PC5_U4TX 0x00021401

    #define GPIO_PD6_U2RX 0x00031801
    #define GPIO_PD7_U2TX 0x00031C01

    int main(void) {

    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    GPIOPinConfigure(GPIO_PD6_U2RX);
    GPIOPinConfigure(GPIO_PD7_U2TX);
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6| GPIO_PIN_7);

    UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 115200,
    (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));
    }

    }

    regards
    karthik
  • Hello Karthik,

    The code for Unlock is missing in the new code post.

    Secondly, for using PuTTy the signals from UART2 have to "physically" come to the PC and after all this to-fro I am not getting even a single line which tells me how you have connected the UART2 Pins to the PC. Please note that by configuring the GPIO's for UART the PC will not get characters from UART2 as physically there is no connection.,

    Regards
    Amit
  • amit,
    sorry the code is this one

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

    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_memmap.h"

    #define GPIO_PD6_U2RX 0x00031801
    #define GPIO_PD7_U2TX 0x00031C01
    void UARTIntHandler(void)
    {
    uint32_t ui32Status;

    ui32Status = UARTIntStatus(UART2_BASE, true); //get interrupt status

    UARTIntClear(UART2_BASE, ui32Status); //clear the asserted interrupts

    while(UARTCharsAvail(UART2_BASE)) //loop while there are chars
    {
    UARTCharPutNonBlocking(UART2_BASE, UARTCharGetNonBlocking(UART2_BASE)); //echo character
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
    SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
    }
    }

    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);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //enable GPIO port for LED
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //enable pin for LED PF2

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

    IntMasterEnable(); //enable processor interrupts
    IntEnable(INT_UART2); //enable the UART interrupt
    UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts

    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) //let interrupt handler do the UART echo function
    {
    // if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
    }

    }

    please tell me with this code pd7 can act as a transmitter or not???

    regards
    karthik
  • Karthik,

    You need to stop harassing Amit with your repeated question of the same thing - you have not provided enough information. Amit has already asked this many times, I'll do it again:
    How have you connected UART2 to your PC?
    The USB cable that you use to program the LaunchPad connects to UART0 and only that - you cannot change it with software.