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.

Problem with using different UART channels(such as UART2) on lm4f120h5qr

I try to send 1 byte via UART2 channel but there is nothing on the channel.I attached the code at down.
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "utils/uartstdio.h"

#include "driverlib/uart.h"

#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
int
main(void)
{
    volatile unsigned long ulLoop;

    //
    // 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_FPULazyStackingEnable();

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

                       
    //
    // 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 & PF3).  
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

                       
    //
    // Initialize the UART.
    //
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
         ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
         SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
 UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
UART_CONFIG_WLEN_8));
    UARTStdioInit(0);



    //
    // Hello!
    //
    UARTprintf("Hello, world!\n");
    
    //
    // We are finished.  Hang around doing nothing.
    //
    while(1)
    {
        //
        // Turn on the BLUE LED.
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

        //
        // Delay for a bit.
        //
        SysCtlDelay(SysCtlClockGet() / 10 / 3);

        //
        // Turn off the BLUE LED.
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
        UARTprintf("Hello, world!\n");
        //
        // Delay for a bit.
        //
        SysCtlDelay(SysCtlClockGet() / 10 / 3);
    }
}

  • If you want to use UART2, you should call UARTStdioInit(2);

    And for my own interest, is there a reason you make calls to both ROM_SysCtlPeripheralEnable and SysCtlPeripheralEnable?  This gets you the worst of both worlds, a slight performance hit and slightly larger code when you call the ROM version, but you also carry the burden of linking in the code for the non-ROM version of the function.

  • slandrum said:

    If you want to use UART2, you should call UARTStdioInit(2);

    And for my own interest, is there a reason you make calls to both ROM_SysCtlPeripheralEnable and SysCtlPeripheralEnable?  This gets you the worst of both worlds, a slight performance hit and slightly larger code when you call the ROM version, but you also carry the burden of linking in the code for the non-ROM version of the function.


    Firstly thanks for your attention secondly,i try to run  example  code with Launchpad default COM port  and there is no data on the UART0 line.Here is the example  code:




    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "utils/uartstdio.h"

    //*****************************************************************************
    //
    //! \addtogroup example_list
    //! <h1>Hello World (hello)</h1>
    //!
    //! A very simple ``hello world'' example.  It simply displays ``Hello World!''
    //! on the UART and is a starting point for more complicated applications.
    //!
    //! UART0, connected to the Stellaris Virtual Serial Port and running at
    //! 115,200, 8-N-1, is used to display messages from this application.
    //
    //*****************************************************************************


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

    //*****************************************************************************
    //
    // Print "Hello World!" to the UART on the Stellaris evaluation board.
    //
    //*****************************************************************************
    int
    main(void)
    {
        volatile unsigned long ulLoop;

        //
        // 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_FPULazyStackingEnable();

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

                           
        //
        // 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 & PF3).  
        //
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

                           
        //
        // Initialize the UART.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
        ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
        ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
        UARTStdioInit(0);

        //
        // Hello!
        //
        UARTprintf("Hello, world!\n");
        
        //
        // We are finished.  Hang around doing nothing.
        //
        while(1)
        {
            //
            // Turn on the BLUE LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

            //
            // Delay for a bit.
            //
            SysCtlDelay(SysCtlClockGet() / 10 / 3);
       UARTprintf("Hello, world!\n");
            //
            // Turn off the BLUE LED.
            //
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
            
            //
            // Delay for a bit.
            //
            SysCtlDelay(SysCtlClockGet() / 10 / 3);
        }
    }
    I didn't change anything on this code (only comment lines and i add UARTPrintf("Hello world\n") in while(1) loop) but like i said there is no data on the UART0 line to my computer.
    Edit:    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7); this line is forgotten mistake by me it must change with   ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

  • Cagri Can Ugur said:
    there is no data on the UART0 line

    And that is no surprise!  Look at your latest post:

        ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
        ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
        ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
        UARTStdioInit(0);

    You mismatch your GPIOPinConfigure (PA0/PA1) with PinType (PIN_6/PIN_7) !  Bit too rapid cut/paste. 

    Further - you've never stated if you had past success via Uart_0 - this would be helpful to those seeking to assist...

    You do realise that launchpad has no RS232 level translators - and should not directly connect to your PC's serial port...

  • My pc doesn't have a serial port and your advice is working on my code.Besides UART0 is a special UART.Launchpad makes a virtual serial port for UART0(i don't know does it work with other UART ports? i think no.) and i've successed to send data on this line.
    And again thanks cb1_mobile i'm looking for 2 days this mistake for UART0.

  • You had all the basics - just needed to connect the dots - good for you.

    Often a 2nd set of eyes will see/note immediately - something which we've missed for days...

  • Be aware!

    As of StellarisWare revistion 9453, the utilities Uartstdio only supports UART0 to UART2 in the UARTStdioInit() call. I had to modify uartstdio.c to support the 8 UARTs on the Stellaris LaunchPad board for my evaluation of the LM4F120.

    Dan