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.

How to use UART0 and UART1 at the same time tm4c123g?

Other Parts Discussed in Thread: EK-TM4C1294XL

HI, i'm a newbie, it will much appreciated if u could help me with these :)

1. After configuring the PB1 and PB0 as UART1 pins, how do I write something on the UART1?

2. If i use UARTprintf ("Hello"), will it be written on UART0 or UART1?

The code i'm going to use to initialise UART1 is:

    SysCtlPeripheralReset(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOB);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);

    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

3. If i want to change the baud rate to 9600, can i just change the value 115200--->9600? Or is there additional steps?

Thanks in advance

  • Hello Richard

    UARTprintf uses UART0 since the configuration uses UARTStdioConfig which calls the uartstdio library in TivaWare. To use UART1 for prints UARTStdioConfig must be called with the first parameter as 1. Also it requires that you have a Level Translator to communicate with a PC. The UART0 works on a LaunchPad as it uses the USB on the ICDI MCU. The default UART0 program can be checked in the following example

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c1294xl\hello

    Also there is another example where UART message can be sent using another API. You can refer to the following example

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c1294xl\uart_echo

    The change of baud rate you have got it right.

    Regards
    Amit
  • Hi Amit thank you so much for your response.

    What i really want to do is that i want to use UART0 for troubleshooting and UART1 to communicate with SIM900.

    How do i write strings into UART0 and UART1? and how do i differentiate both?
  • Hello Richard,

    You may want to use UARTCharPut API for UART1 while retaining UARTprintf for Serial Console Debug.

    Regards
    Amit
  • Richard Fanny said:
    What i really want to do...

    Would it not have made more sense to list, "What you really wanted to do," far sooner?

    Basic time/effort spent reading the many UART code examples proves best in achieving your, (unexpressed) - yet "real" wants!

  • Thank you cb for your wise yet helpful advise :)