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.

CC2642R: cannot enable 2 channel Uart2

Part Number: CC2642R
Other Parts Discussed in Thread: SYSCONFIG

Hi engineers,

SDK version: 6.40

set: CC2642 LP

I use sysconfig and enable 2 channel uart2, thenI use UART2_open(CONFIG_UART2_0), UART2_open(CONFIG _UART2_1).

But when I use UART2_write() to the handle of UART_open, only CONFIG _UART2_1 is functional, no data from CONFIG_UART2_0. I confirmed they are both functional when I enable either one separately.

Could you help me understand if I did something wrong here? 

  • Hi Simon,

    Here is a modified version of uart2callback which I verified to be capable of communicating on both UART peripherals.  The only change in SysConfig was adding the second UART module.

    /*
     * Copyright (c) 2020, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== uart2callback.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    
    /* POSIX Header files */
    #include <semaphore.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART2.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    static sem_t sem;
    static volatile size_t numBytesRead;
    static volatile bool two;
    
    /*
     *  ======== callbackFxn ========
     */
    void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
    {
        if (status != UART2_STATUS_SUCCESS)
        {
            /* RX error occured in UART2_read() */
            while (1) {}
        }
    
        two = 0;
        numBytesRead = count;
        sem_post(&sem);
    }
    
    void callbackFxn2(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
    {
        if (status != UART2_STATUS_SUCCESS)
        {
            /* RX error occured in UART2_read() */
            while (1) {}
        }
    
        two = 1;
        numBytesRead = count;
        sem_post(&sem);
    }
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        char input;
        const char echoPrompt[] = "Echoing characters:\r\n";
        UART2_Handle uart;
        UART2_Handle uart2;
        UART2_Params uartParams;
        int32_t semStatus;
        uint32_t status = UART2_STATUS_SUCCESS;
    
        /* Call driver init functions */
        GPIO_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        /* Create semaphore */
        semStatus = sem_init(&sem, 0, 0);
    
        if (semStatus != 0)
        {
            /* Error creating semaphore */
            while (1) {}
        }
    
        /* Create a UART in CALLBACK read mode */
        UART2_Params_init(&uartParams);
        uartParams.readMode     = UART2_Mode_CALLBACK;
        uartParams.readCallback = callbackFxn;
        uartParams.baudRate     = 115200;
    
        uart = UART2_open(CONFIG_UART2_0, &uartParams);
        uartParams.readCallback = callbackFxn2;
        uart2 = UART2_open(CONFIG_UART2_1, &uartParams);
    
        if (uart == NULL)
        {
            /* UART2_open() failed */
            while (1) {}
        }
    
        if (uart2 == NULL)
        {
            /* UART2_open() failed */
            while (1) {}
        }
    
        /* Turn on user LED to indicate successful initialization */
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
        /* Pass NULL for bytesWritten since it's not used in this example */
        UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);
        UART2_write(uart2, echoPrompt, sizeof(echoPrompt), NULL);
    
        /* Pass NULL for bytesRead since it's not used in this example */
        status = UART2_read(uart, &input, 1, NULL);
        status = UART2_read(uart2, &input, 1, NULL);
    
        /* Loop forever echoing */
        while (1)
        {
            numBytesRead = 0;
    
            if (status != UART2_STATUS_SUCCESS)
            {
                /* UART2_read() failed */
                while (1) {}
            }
    
            /* Do not write until read callback executes */
            sem_wait(&sem);
    
            if (two == 0)
            {
                if (numBytesRead > 0)
                {
                    status = UART2_write(uart, &input, 1, NULL);
    
                    if (status != UART2_STATUS_SUCCESS)
                    {
                        /* UART2_write() failed */
                        while (1) {}
                    }
                }
                status = UART2_read(uart, &input, 1, NULL);
            }
            else if (two == 1)
            {
                if (numBytesRead > 0)
                {
                    status = UART2_write(uart2, &input, 1, NULL);
    
                    if (status != UART2_STATUS_SUCCESS)
                    {
                        /* UART2_write() failed */
                        while (1) {}
                    }
                }
                status = UART2_read(uart2, &input, 1, NULL);
            }
        }
    }
    

    Regards,
    Ryan