Tuesday, June 16, 2020

How to use two UARTs in CC26x2 and CC13x2.

The following steps show you how to enable second UART in CC26x2 and CC13x2 using uartecho example.

1. Add second UART CONFIG_UART_1 from syscfg with the following steps



2. Add the following red codes to use CONFIG_UART_1.

void *mainThread(void *arg0)
{
    char        input;
    const char  echoPrompt[] = "Echoing characters:\r\n";
    const char  echo1Prompt[] = "UART 2 Echoing characters:\r\n";
    UART_Handle uart;
    UART_Params uartParams;
    UART_Handle uart1;
    UART_Params uart1Params;


    /* Call driver init functions */
    GPIO_init();
    UART_init();

    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* Turn on user LED */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.baudRate = 115200;

    uart = UART_open(CONFIG_UART_0, &uartParams);

    if (uart == NULL) {
        /* UART_open() failed */
        while (1);
    }

    /* Create second UART with data processing off. */
    UART_Params_init(&uart1Params);
    uart1Params.writeDataMode = UART_DATA_BINARY;
    uart1Params.readDataMode = UART_DATA_BINARY;
    uart1Params.readReturnMode = UART_RETURN_FULL;
    uart1Params.baudRate = 115200;

    uart1 = UART_open(CONFIG_UART_1, &uart1Params);

    if (uart1 == NULL) {
        /* UART_open() failed */
        while (1);
    }

    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    UART_write(uart1, echo1Prompt, sizeof(echo1Prompt));

    /* Loop forever echoing */
    while (1) {
        if(UART_read(uart, &input, 1))
            UART_write(uart, &input, 1);
    }

3. Build and run uartecho and now you can see "UART 2 Echoing characters:" output from the seconds UART TX pin.

No comments:

Post a Comment