Jump to content
43oh

UART problem


Recommended Posts

I'm trying to get a simple uart program working as shown below and I'm having issues with the baud rate being 9600. The program works fine with the baud rate being 115200. The code is based on the code provided in the Stellaris workbook.

#include <inc/hw_gpio.h>
#include <inc/hw_memmap.h>
#include <inc/hw_sysctl.h>
#include <inc/hw_types.h>
#include <driverlib/gpio.h>
#include <driverlib/rom.h>
#include <driverlib/sysctl.h>
#include <driverlib/uart.h>

int main()
{
    // Set clock to 80 Mhz.
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL |
                       SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    // Set Port A to UART.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    // Set Rx/Tx pins for UART.
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    // Initialize UART.
    ROM_UARTConfigSetExpClk(UART0_BASE, (ROM_SysCtlClockGet()), 9600,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

    // Send data.
    char *str = "hello world!\r\n";
    while(*str)
        ROM_UARTCharPut(UART0_BASE, *str++);

    // Disable UART.
    ROM_UARTDisable(UART0_BASE);

    // Set PB2 to output.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2);

    while(1)
    {
        // Toggle between on and off with a delay.

        // Turn on led.
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, ~GPIO_PIN_2);
        ROM_SysCtlDelay(10000000);

        // Turn off led.
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_PIN_2);
        ROM_SysCtlDelay(10000000);
    }
}

With the baud rate at 115200, I don't get garbage from the serial port (the attached screenshots are from a bunch of resets). Wit the baud rate at 9600, I get garbage most of the time. It's not a big deal for me that the uart doesn't work with the baud rate at 9600, but I'm wondering why it's not working. Also, are there values that definitely work or do they depend on the clock speed?

 

Btw, I'm using gcc as my compiler from https://launchpad.net/gcc-arm-embedded on Windows and I use a makefile based on https://github.com/Wollw/stellaris-launchpad-template-gcc/blob/master/Makefile.

post-1791-14264605285528_thumb.png

post-1791-14264605285863_thumb.png

Link to post
Share on other sites

I have not tried this personally.  However, you are using UART0 which is connected to the ICDI microcontroller.  The baud rate therefore must match between the ICDI microcontroller and the target.

 

It is possible that the ICDI is not correctly changing its baud rate to match the settings in PuTTY.  At a minimum the ICDI will come out of reset or power up with settings at 115200 and it may just not be in sync with PC.

 

You could try sending characters in PuTTY and see with a scope what baud rate they get sent from the ICDI to the target.  The test points are near the reset button TXD and RXD is the link from UART target to UART ICDI.

 

 

Dellwood

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...