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.

Need help with problem turning on UART1-7

Other Parts Discussed in Thread: TM4C123GH6PM

I tried to modify the uart_echo example to use UART2. However, nothing comes out on UART2. I verified this with an oscilloscope. In fact, none of the UARTs work except UART0 which does work. I read in another post that I need to turn on the gated clocks to the UARTs by writing to the RCGCUART register at 0x400fe618, but that didn't help. I also changed the interrupt table in startup_rvmdk.S to handle an interrupt on UART2. According to the debugger, the code gets to the while loop at the end, which means it's not off in the weeds somewhere.

The relevant portion of my code is shown below. Can anyone please help? TIA.

...

// set RCGCUART
volatile uint32_t value=0;
value = (*((volatile uint32_t *)0x400FE618));
(*((volatile uint32_t *)0x400FE618)) = 0x000f;
value = (*((volatile uint32_t *)0x400FE618));

//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);

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

//
// Set GPIO A0 and A1 as UART pins.
//
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6);
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, 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 *)"Enter text: ", 12);


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

...

  • Hi Osman,

    First of all I would need information on which TM4C device are you using.

    Secondly, if it is TM4C123 then PD7 which is UART2_TX Pin, is a locked pin. You will have to unlock the Pin and then should be able to configure it for UART2 TX Pin.

    Also for the remaining UARTs can you please send the value of the PPUART register at 0x400FE318 address. This should be useful.

    Amit

  • Amit, your comment about the locked pins lead me to a solution. I am using the TM4C123 evaluation kit. I generated code using the Pin Mux utility, and saw these two lines in the output code:

    HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x80;

    I added them to my code, and now UART2 works! Thanks for pointing me in the right direction.

    Osman

  • Hi Osman,

    You did mention that UART1-7 were also not working. Any update on the same?

    Amit

  • Yes, the UARTs now work. I tested UART2 on PORTD and UART3 on PORTC. Both work. The key was to unlock the pins. The clock gating had nothing to do with the problem.

  • Osman Eralp said:

    HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x80;

    I added them to my code, and now UART2 works!

    Should that prove the case - it is not due to any attempt to, "unlock" PC7 (represented by your code block, quoted above) - which has never appeared in need of any such unlock assistance... (PD7 more "welcomes" such escape from NMI)

    And - as others have suggested - the single/proper "unlock" of PD7 should have had no effect upon the UART behavior of multiple, other UART Ports - which you represent now as, "working."  Proper correction descriptions (but for PD7) are nowhere, "in evidence," thus others visiting here receive minimal benefit...

     

  • Osman Eralp said:

    HWREG(GPIO_PORTC_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTC_BASE + GPIO_O_CR) = 0x80;

    I added them to my code, and now UART2 works!

    Sorry, I meant to say that UART3 works. UART2 is on PORTD, which is not affected by the unlock commands above. I was testing so many UARTs I got them mixed up!

    Thanks again to Amit for pointing out that the port pins need to be unlocked.

  • No one seeks sorrow - new visitors would likely be confounded by that unneeded, PC7 "exercise."

    Earlier you listed multiple UARTs as being DOA.  (i.e. dead)  Might you provide some detail as to how you restored all of those not "rescued" by the unlocking of PD7?  Surely others visiting here would benefit...

    And - that unlocking procedure (PD7 & PF0) was first listed here - several years back (repeatedly) by this reporter...  Forum search reveals... 

  • For using assignments there are two headers should be included

    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    
    HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80;


    When I included these strings I also got UART2 port working with using PD7. For testing purposes I loop invitation without any interrupts. Interrupts are  disabled. However, it works only if the code downloaded right after the uart_echo example. If I take power off and switch it on again the code is not working. The Uart_echo works without any problem whether I download it again or just powering it up. I check the TX pin with a scope.

    Let me know if you need to look the code. 

  • Hi Igor,

         You can do a search in the forum for PD7 unlocking code. This have been discussed here several times already.

    -kel

  • Hi Amit

    I am working with tm4c123gh6pm 's uart module.I am just trying to send some data to my hyperterminal.My code is working fine for UART0 module.But while i want to use other uart modules i am not getting any data on my hyper terminal.As you suggested I have unlocked the pin also for particular Uart.Still it is not working.I am posting my code below.I am using ccs v5Please.help me out here.


    #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"
    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"

    //*****************************************************************************

    //
    //*****************************************************************************
    int
    main(void)
    {
    char cThisChar;

    //

    //
    HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTB_BASE + GPIO_O_CR) =GPIO_PIN_1;
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    /*
    //HWREG(GPIO_PORTB_BASE + GPIO_O_PCTL) = 0x00;
    HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
    HWREG(GPIO_PORTB_BASE + GPIO_O_CR) = GPIO_PIN_1;
    //HWREG(GPIO_PORTB_BASE + GPIO_O_AFSEL) &= ~GPIO_PIN_1; // Alt Funct Select
    HWREG(GPIO_PORTB_BASE + GPIO_O_DEN) |= GPIO_PIN_1; // Digital Enable
    //HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = 0;

    */


    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ);

    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);

    // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);


    //
    // UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
    UART_CONFIG_PAR_NONE));

    UARTCharPut(UART1_BASE, 'n');


    while(1);
    return(0);
    }

    Thanks and regards

    Arun

  • Hello Arun,

    Are you using the DK or EK boards or a custom board?

    Regards

    Amit