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.

LP-CC2652R7: Display_open() and UART2_open() simultaneously?

Part Number: LP-CC2652R7


I have the desire to use the TI display driver to get Display_printf() out the Uart. I have this working.
I have the desire to use the UART2 driver to read characters coming into the Uart. I have this working.
However, not both at the same time. It’s one or the other. In other words, it does not appear possible for the system to do both Display_open() and UART2_open() even though the former is used only to write bytes out the Uart, and the latter to read bytes in from the Uart. How can I work around this constraint?

  • Note: after hours and hours I finally arrived at the following logic that appears to give me what I want. This resolves my issue.

    #include <ti/drivers/UART2.h>
    #include <ti/display/DisplayUart2.h>
    #include <ti/display/Display.h>
    #include "ti_drivers_config.h"

    typedef void (*IncomingUartChar_CallBackType)(char IncomingUartChar);
    Display_Handle display; /* Used by the various Display_printf() macros */
    static char rxBuf[20];
    static IncomingUartChar_CallBackType CachedClientCallback;

    static void uartRxCallback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
    {
        /* Note: this Callback runs in interrupt context. */
        memcpy(rxBuf,buf,count);
        CachedClientCallback(rxBuf[0]); /* Forward the incoming character along... */
        UART2_read(handle, &rxBuf, 1, NULL);
    }

    void SetupSystemPrintf(IncomingUartChar_CallBackType ClientCallback_ForAnyIncomingUartBytes)
    {
        {   /* Note: This sets up so that Display_printf() will push bytes out the UART. */
            Display_init(); // Requires Display_config structure of the auto-derived ti_drivers_config.c source file.
            display = Display_open(Display_Type_UART, NULL);
        }
        {   /* Note: Here we tweak the UART that has been set up by Display_open(); e.g. change the read
                     mode to UART2_Mode_CALLBACK and set the readCallback so that we can have visibility
                     to any character coming into the UART. The Display driver doesn't care about incoming
                     characters as it is just focused on sending characters out as per our Display_printf()
                     calls. But characters coming in are something the Client might want to process; so if
                     the caller has supplied a ClientCallback we'll forward those chars on. These would be
                     characters that are typed by a user at the external terminal window that provides input
                     to the UART.
            */
            if (display && ClientCallback_ForAnyIncomingUartBytes) {
                CachedClientCallback = ClientCallback_ForAnyIncomingUartBytes;
                DisplayUart2_Object *object = (DisplayUart2_Object *)display->object;
                UART2_Handle Uart2Handle = object->hUart;
                UART2_Object* uart2Object = Uart2Handle->object;
                if (uart2Object) {
                    uart2Object->readCallback = uartRxCallback;
                    uart2Object->state.readMode = UART2_Mode_CALLBACK;
                    {   /* Do a UART2_read() to prime things. Then whenever the first
                           char arrives the readCallback() will keep things going.
                        */
                        UART2_read(Uart2Handle, &rxBuf, 1, NULL);
                    }
                }
            }
        }
    }

  • Hi,

    Thank you for sharing your solution.

    Best regards,