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.

Help, Enable the UART 2!

I can use this code for the UART0 and turn on three leds by "a" "b" "c", but when i chang the UART, it can not turn on and receive anything! I usse he USB UART to connect to the UART2, I try to another UART1 but it still as UART2.

Anyone can help me!

#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 "driverlib/rom.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"


void UARTIntHandler(void)
{
uint32_t ui32Status; // THIS PARAMETER CONTAINS THE STATUS OF UART

ui32Status = UARTIntStatus(UART1_BASE, true); // GET THE INTERRUPT STATUS

UARTIntClear(UART1_BASE, ui32Status);

}

int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);


SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); //ENABLE THE UART0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //ENABLE THE GPIOA


GPIOPinConfigure(GPIO_PD6_U2RX); //CONFIGURE THE GPIO AS THE UART
GPIOPinConfigure(GPIO_PD7_U2TX); //CONFIGURE THE GPIO AS THE UART
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1); //CONFIGURE THE GPIO 0 AND 11 AS THE UART

//ENABLE THE GPIOF AND THE PIN 2 FOR THE BLUE
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_1|GPIO_PIN_2);


UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // ALLOW TO CONFIGURE THE PARAMETERS OF UART

// ALLOW INTERRUPT FOR ALL
IntMasterEnable(); // ENABLE INTERRUPT FOR PROCESSOR
IntEnable(INT_UART2); //ENABLE INTERRUPT UART
UARTIntEnable(UART2_BASE, UART_INT_RX|UART_INT_RX); // ENABLE THE INTERRUPT FOR RX AND TX ONLY


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, ' ');
// UARTSend((uint8_t*)"Enter text:", 11); // SEND MANY CHARACTER IN ONE TIME

while(1)
{
while(UARTCharsAvail(UART2_BASE)) // WAIT UNTIL THE THE PORT RECEIVE THE INPUT
{ int32_t v = UARTCharGetNonBlocking(UART2_BASE);
UARTCharPutNonBlocking(UART2_BASE, UARTCharGetNonBlocking(UART2_BASE)); // ECHO CHARACTER
if (v=='a')
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); // THE SIGNAL FOR THE DATA COMING
SysCtlDelay(SysCtlClockGet()/100); // DELAY 1 MILI SECOND
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); // TURN OFF THE LED
}
if (v=='b')
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // THE SIGNAL FOR THE DATA COMING
SysCtlDelay(SysCtlClockGet()/100); // DELAY 1 MILI SECOND
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); // TURN OFF THE LED
}
if (v=='c')
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1); // THE SIGNAL FOR THE DATA COMING
SysCtlDelay(SysCtlClockGet()/100); // DELAY 1 MILI SECOND
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); // TURN OFF THE LED
}

}

//if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
}

}

  • Huu Lam Pham said:
    I use the USB UART to connect to the UART2, I try to another UART1 but it still as UART2.

    Might your "USB UART" suggest a proper, USB to UART converter?    If that's the case have you monitored the signal output from the converter - at the converter's UART output while sending from the PC?    (such should be first order of business - to my mind)

    If "USB UART" does not suggest an independent, proper, USB to UART converter - read on.  

    My friend - do you realize that only UART0 connects to your board's (assumed LPad) UART to USB converter?    Thus - without a similar such "UART to USB" converter - you are unlikely to realize communication to your (assumed, again) PC.   Except for UART0 - no other UARTs pass thru such a converter - thus all of these other UARTs can only manage similar, "UART to UART" communication.    Is that clear?

    Now my firm still has RS232 ports on several of our PCs.   Note that you may not (directly) connect RS232 signal levels to your MCU!   (a Cmos to RS232 level shifter is required - not an option - MUST be used to prevent damage.)

    You'd improve understanding by a careful review of your board's schematic diagram.   That highlights, "What goes where" - and you'll note that (only) UART0 may readily connect to the "outside world" via USB.

    Many low cost UART to USB converters are commercially available - some even fully contain the conversion w/in the cable...   (as some have noted, "launch" indeed...)

  • Hello Huu,

    The issue is that if it is TM4C123 then the port-pin PD7 is locked. You would need to unlock the port-pin before running the following line,

    GPIOPinConfigure(GPIO_PD7_U2TX); //CONFIGURE THE GPIO AS THE UART
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1); //CONFIGURE THE GPIO 0 AND 11 AS THE UART

    Regards
    Amit
  • Huu Lam Pham said:
    it can not turn on and receive anything! I usse he USB UART to connect to the UART2, I try to another UART1 but it still as UART2.

    Hi Amit,

    Perhaps not so simple as (only) [usual PD7] as villain!    Note that poster:

    a) states he cannot receive - thus unless PD7 (a UART TX) serves to disable UART RX - that proves questionable

    b) poster notes same condition upon UART1.   (where PD7's "attack" is muted)

    I remain uncertain if a "real & functioning" USB to UART converter has been employed...

  • Hello cb1,

    Point noted. Seems that the USB2UART converter information has to be posted...

    Regards
    Amit
  • I have unlocked the PD7 but the PD6 still can not receive anything, when i press the Reset, the PD7 send "enter text: ", but the led still not blink when i input the value!
  • Huu Lam Pham said:
    ...have unlocked PD7...PD6 still can not receive anything ... when Reset - PD7 sends "enter text:

    Well - hopefully - good that.   Yet - the report of "sending" is less valuable than your report of having "received" that very "sending."   Please read that last sentence several times - as the correct answer best enables those here to assist you.   If you can successfully (really) transmit & receive that data remotely - then it is sure you've properly enabled your UART - your communication medium is intact - and your baud rate & other protocols appear matched.

    Looking at your code I note:

    GPIOPinConfigure(GPIO_PD6_U2RX); //CONFIGURE THE GPIO AS THE UART
    GPIOPinConfigure(GPIO_PD7_U2TX); //CONFIGURE THE GPIO AS THE UART
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1); //CONFIGURE THE GPIO 0 AND 11 AS THE UART

    Look at my highlights - should not those "pinconfigures" match the "pintypes?"   If this is (really) your code - it is hard to imagine that PD7 successfully transmitted.

    Both Amit & I have asked that you confirm that a (real) USB to UART converter is in use.   (not that supplied upon the eval board)   If - after you correct your code - you still cannot receive the use of a scope to monitor the incoming signal will prove most helpful.

  • 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) |= 0x80;
    HWREG(GPIO_PORTD_BASE + GPIO_O_AFSEL) &= ~0x80;
    HWREG(GPIO_PORTD_BASE + GPIO_O_DEN) |= 0x80;
    HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;

    GPIOPinConfigure(GPIO_PD6_U2RX);
    GPIOPinConfigure(GPIO_PD7_U2TX);
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x00;
    HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;


    Sorry about the above code, i write the wrong code, but i correct the code right after i post this topic!
  • We note that (still) you do not state (at all) the presence or absence of a (real) external USB to UART converter! This frustrates all helpers.
    And - might the (unnecessary and likely destructive) "repetition" of PD7's "unlock" have "spoiled" your earlier PD7 as UART set-up? One (early) unlock is all that's required.
  • Hello cb1

    Looks like the last post suggests that the issue was on the configuration and may be in the flurry of experiments incorrect observations were made. And the "critical" detail on external protocol converter will plague this thread

    Regards
    Amit
  • Hello to you, Amit,

    We've both asked for that (necessary) answer - to silence!

    And then - we learn that poster realized a post was incorrect - yet allowed it to remain.

    ...To the poster: "Clicking the "More box" - at the bottom of your post - will reveal an "Edit" option - which enables you to correct and/or modify an earlier post.