Jump to content
43oh

LM4F120H5QR: Use UART1/2


Recommended Posts

Hi together,

 
I am trying to get UART working on my Stellaris Launchpad (LM4F120H5QR) using the onboard PIN headers (UART1/2) instead of the USB cable (UART0). This is how my code looks like (based on uart_echo from StellarisWare). I am using a FOCA tiny break-out board (integrating a FT232 IC) to receive the data on my terminal software. Currently, I am trying to set up UART1 and GPIOB (PB0 / PB1). However, I do not receive anything on my temrinal software, while using the standard uart_echo code for UART1 it works properly.
 
Can somebody tell me what I am missing? If this works, I am getting closer to my actual goal, which is enabling and using UART1/2 in ASM.
 
Best regards

 

uart_echo.c

uart_echo.c 
int main(void)
{
    //
    // 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_FPUEnable();
    ROM_FPULazyStackingEnable();

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

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

 
		//
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

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

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);
    ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART1);
    ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
				UARTSend((unsigned char *)"Hello World!\n", 13);
    }
} 

And I changed the corresponding values in the Startup file to the following values:

 

startup_rvmdk.S

...
...
DCD     IntDefaultHandler           ; The PendSV handler
DCD     IntDefaultHandler           ; The SysTick handler
DCD     IntDefaultHandler           ; GPIO Port A
DCD     IntDefaultHandler           ; GPIO Port B
DCD     IntDefaultHandler           ; GPIO Port C
DCD     IntDefaultHandler           ; GPIO Port D
DCD     IntDefaultHandler           ; GPIO Port E
;DCD     UARTIntHandler             ; COMMENTED OUT ... UART0 Rx and Tx
;DCD     IntDefaultHandler          ; COMMENTED OUT ... UART1 Rx and Tx
DCD     IntDefaultHandler           ; UART0 Rx and Tx
DCD     UARTIntHandler              ; UART1 Rx and Tx
Link to post
Share on other sites
  • 2 weeks later...

I guess you have tried already but, it should be something like this. UART2 RX and TX are pinned to D6 and D7 respectively, so:

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

    // Set GPIO D6 and D7 as UART pins.
    GPIOPinConfigure(GPIO_PD6_U2RX);
    GPIOPinConfigure(GPIO_PD7_U2TX);
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_6 | GPIO_PIN_7);
	
	UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));
//enable interrupts ...

Also, Is there any special reason you need to use the ROM_* functions?

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...