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.

LM3S6911 UART howto

Prodigy 50 points

Replies: 8

Views: 2972

Hi there:

I am a newbie at this kind of things, so I ask for your patience here. I am sure someone out there will tell me this is easy.

Here's my code:

Code:


 
#include "utils/uartstdio.h"
#include "inc/lm3s6911.h"
#include "inc/hw_types.h"
#include "sysctl.h"
#include "uart.h"
#include "hw_memmap.h"

#define printf UARTprintf

int main()
{
    
SysCtlClockSet(SYSCTL_SYSDIV_1 SYSCTL_USE_OSC SYSCTL_OSC_MAIN SYSCTL_XTAL_6MHZ);

    
UARTStdioInit(UART1_BASE);
    while(
1)
    {
        
printf("HelloWorld
"
);
    }
}






The goal is pretty straightforward - I just want to print something out. I am using Keil for ARM on simulator for the lm3s6911.

The program compiles fine, links fine and, as far as I know, runs fine too. But I just don't see the HelloWorld message popping up in Keil for ARM's UART windows (any three of them).

Obviously, I downloaded StellarisWare, I am compiling uartstdio.c. I also put C:StellarisWaredriverlibrvmdkdriverlib.lib as part of my libraries.

Can somebody help me out?

8 Replies

  • Download the StellarisWare distribution for the EKK-LM3S9B90 and look at the hello demo application.

    Basically, what you're missing is..

    1. Enable GPIO port A.
    (see SysCtlPeripheralEnable())

    2. Configure the GPIO port A pins PA0 and PA1 as UART.
    (see GPIOPinTypeUART())

    3. Initialize the UART.
    (see UARTStdioInit())

    4.Print the string out the UART.
    (see UARTprintf())

    As an admitted newbie, I highly recommend that you look through the example applications provided with StellarisWare. Moreover, I encourage you to use StellarisWare function calls for your first few applications. As you gain proficiency with the peripherals you can use the contents of the provided APIs to optimize your applications where needed. You should find the code very easy to read and understand.
  • TI scott wrote:
    Basically, what you're missing is..

    1. Enable GPIO port A.
    (see SysCtlPeripheralEnable())

    2. Configure the GPIO port A pins PA0 and PA1 as UART.
    (see GPIOPinTypeUART())


    That's what the comment describing UARTStdioInit in uartstdio.c means when it says:

    //*****************************************************************************
    //
    //! Initializes the UART console.
    //!
    //! param ulPortNum is the number of UART port to use for the serial console
    //! (0-2)
    //!
    //! This function will initialize the specified serial port to be used as a
    //! serial console. The serial parameters will be set to 115200, 8-N-1.
    //!
    //! This function must be called prior to using any of the other UART console
    //! functions: UARTprintf() or UARTgets(). In order for this function to work
    //! correctly, SysCtlClockSet() must be called prior to calling this function.
    //!
    //! It is assumed that the caller has previously configured the relevant UART
    //! pins for operation as a UART rather than as GPIOs.

    //!
    //! return None.
    //
    //*****************************************************************************
    void
    UARTStdioInit(unsigned long ulPortNum)


    Post edited by: awneil, at: 2009/07/11 01:07
  • Note also the specification for the parameter to UARTStdioInit: it's the UART number - not the peripheral base address:

    //*****************************************************************************
    //
    //! Initializes the UART console.
    //!
    //! param ulPortNum is the number of UART port to use for the serial console
    //! (0-2)

    //!
    //! This function will initialize the specified serial port to be used as a
    //! serial console. The serial parameters will be set to 115200, 8-N-1.
    //!
    //! This function must be called prior to using any of the other UART console
    //! functions: UARTprintf() or UARTgets(). In order for this function to work
    //! correctly, SysCtlClockSet() must be called prior to calling this function.
    //!
    //! It is assumed that the caller has previously configured the relevant UART
    //! pins for operation as a UART rather than as GPIOs.

    //!
    //! return None.
    //
    //*****************************************************************************
    void
    UARTStdioInit(unsigned long ulPortNum)


    So your code should look something like this:

    Code:


     
    int
    main
    (void)
    {

        
    //
        // Set the system clock to run at 8 MHz from the main oscillator.
        //
        
    SysCtlClockSet(SYSCTL_SYSDIV_1 SYSCTL_USE_OSC |
                       
    SYSCTL_XTAL_8MHZ SYSCTL_OSC_MAIN);

        
    //
        // Enable the peripherals used by this example.
        //
        
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);


        
    //
        // UART0: Set GPIO A0 and A1 as UART.
        //
        
    GPIOPinTypeUART(GPIO_PORTA_BASEGPIO_PIN_0 GPIO_PIN_1);


        
    //
        // Initialize UART0 as a console for text I/O.
        //
        
    UARTStdioInit(0);


        
    //
        // Print hello message to user.
        //
        
    UARTprintf"
    Hello, world!
    );

        for( ;; ) 
    /* Stop here! */;
    }





    Which is lifted pretty much verbatim from a Luminary (now TI) sample!
  • Thank you both for your help. Unfortunately, I am still stuck.

    1- I tried to run the Hello example for the lm39b90 as recommended. The example compiles fine, but when running, I have a memory access fault at ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    I tried quite a few things, including changing the frequency (I noticed my settings were at 8Mhz, while the program seems to suppose 16Mhz), but in vain. I also tried to use SysCtlClockSet, but it fails on that function call too.

    2- I also tried the code you posted. It compiles, links and runs without fault. But, I cannot see the HelloWorld anywhere within the three UART windows in Keil. There also I tried a few things, including trying to use UART1 instead, but so far without success.

    Could it be that I need to set up something in my environment? I checked - I am using the lm3s6911 simulator.
  • skidooman wrote:
    I cannot see the HelloWorld anywhere within the three UART windows in Keil. There ... I am using the lm3s6911 simulator.
    Do you have an lm3s6911 board?

    If so, does it work on the board?
  • Unfortunately no, I just have the simulator.

    Perhaps there is a difference...
  • Actually, I think that I know what is going on. The program is fine, however the listening window is not.

    Keil reports that UART 0 status is:

    INVALID baud, 8 Data Bits, 1 Stop Bits, No Parity; TX, RX Pins DISABLED
  • That was my own inexperience speaking. Actually, I verified that the UART 0 port is being activated correctly upon execution. It shows the right baud speed and all.

    And the execution does not encounter any faults.

    But I cannot see the output within Keil's 3 UART windows still. :(

    I am not sure why. I feel the solution is at hand, just eluding me a bit. I tried to read everything I could get my hands on, but no cigar.

    If someone out there has an idea plese let me know.

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.