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.

EK-LM3S9B92-B echo sample on uart1

Hi,
I'm trying to convert "uart echo sample" to work with uart1 PORTC6 and PORTC7, with no success.
I'm using IAR compiler with board EK-LM3S9B92-B. The ports are connected to RS232 Transciever to my PC.
The same following code is working OK on uart0 PORTA_0 PORTA_1.

int
main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

IntMasterEnable();

GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

UARTSend((unsigned char *)" 33[2JEnter text: ", 16);

while(1)
{

while(ROM_UARTCharsAvail(UART1_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
UARTCharPutNonBlocking(UART1_BASE, UARTCharGetNonBlocking(UART1_BASE));
}


}
}

Thanks in advance.
  • This code looks fine but there is one thing you've not done that is rather critical. On the lm3s9b92, you have the option of picking which peripheral signals appear on particular pins. UART0 is the default function on PA0/1 but UART1 is not connected to PC6/7 by default so you need to set the port control register to enable those signals. Do this with the following somewhere near the top of your program:
    Code:


     
    HWREG
    (GPIO_PORTC_BASE GPIO_O_PCTL) = 
      (
    HWREG(GPIO_PORTC_BASE GPIO_O_PCTL) &
       ~(
    GPIO_PCTL_PC6_M GPIO_PCTL_PC7_M)) |
      (
    GPIO_PCTL_PC6_U1RX GPIO_PCTL_PC7_U1TX);






    You will need to include "inc/hw_gpio.h" to get these definitions.
  • Looking at your code again, I see one other thing that is perhaps a bit strange:

    Code:


     UARTCharPutNonBlocking(UART1_BASEUARTCharGetNonBlocking(UART1_BASE));





    Since UARTCharGetNonBlocking() will return immediately if no character is waiting, you will be continually writing 0xFF to the transmitter when the receiver is idle. Is that what you intend? If you made this call a UARTCharGet() instead, it would block until it had something valid to retransmit.
  • Thanks a lot.
    it works.