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.

LAUNCHXL-CC1310: Not receiving the byte properly in UART in Callback mode.

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

Hello,

I am working on "UART" of CC1310 LP and with collector code.

CCS Version 10

simplelink_cc13x0_sdk_4_20_00_05.

I am missing out some character as shown in below shared screenshot those characters are replaced with <0x80>.

In some cases , when i am debugging by placing breakpoint at line no 6(If statement)  in uartRxCallback function then i am getting the desired output.

  

const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1310_LAUNCHXL_UARTCOUNT] = {
    {
        .baseAddr       = UART0_BASE,
        .powerMngrId    = PowerCC26XX_PERIPH_UART0,
        .intNum         = INT_UART0_COMB,
        .intPriority    = ~0,
        .swiPriority    = 0,
        .txPin          = CC1310_LAUNCHXL_UART_TX,
        .rxPin          = CC1310_LAUNCHXL_UART_RX,
        .ctsPin         = PIN_UNASSIGNED,
        .rtsPin         = PIN_UNASSIGNED,
        .ringBufPtr     = uartCC26XXRingBuffer[CC1310_LAUNCHXL_UART0],
        .ringBufSize    = sizeof(uartCC26XXRingBuffer[CC1310_LAUNCHXL_UART0]),
        .txIntFifoThr   = UARTCC26XX_FIFO_THRESHOLD_1_8,
        .rxIntFifoThr   = UARTCC26XX_FIFO_THRESHOLD_1_8,
        /* .rxIntFifoThr   = UARTCC26XX_FIFO_THRESHOLD_7_8, */
        .errorFxn       = NULL
    }
};

Uart parameter configuration.

#if defined(BOARD_DISPLAY_USE_UART)
    /* Enable System_printf(..) UART output */
    UART_init();
    UART_Params_init(&uartParams);
#ifndef TIMAC_AGAMA_FPGA

    //uartParams.writeMode = UART_MODE_CALLBACK;
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = &uartRxCallBack;
    uartParams.writeDataMode = UART_DATA_TEXT;
    uartParams.readDataMode = UART_DATA_TEXT;
    uartParams.readReturnMode = UART_RETURN_NEWLINE;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;

#else
    uartParams.baudRate = 460800;
#endif

    UartPrintf_init(UART_open(Board_UART0, &uartParams));
    /*UART_control(hUart, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);*/

#endif /* BOARD_DISPLAY_USE_UART */

This is uartRxCallBack function in which i am receiving byte by byte data and storing it in "buff"  array.

Shared the uartsRxCallBack snippet below.

 

void uartRxCallBack(UART_Handle handle, void *Rx_char, size_t size)
{
    /* buff is a global char array of 64 bytes */

    buff[idx] = *(uint8_t*) Rx_char;
    if (buff[idx] == '\r')
    {
        MsgObj msg;
        msg.id = 0x19;

        /* String Terminating */
        buff[idx] = '\0';

        /* Passing address of string */
        msg.val = buff;
        idx = 0;

        /* memset(buff, 0x00, sizeof(buff)); */

        Mailbox_post(mbxHandle, &msg, BIOS_NO_WAIT);
    }
    else
    {
        idx++;
    }
    UART_read(handle, &Rx_char, 1);
}

Void MailTaskFxn(UArg a0, UArg a1)
{

    Mailbox_Params_init (&mbxParams);
    mbxParams.buf = &mailboxBuffer;
    mbxParams.bufSize = sizeof(mailboxBuffer);
    Mailbox_construct(&mbxStruct, sizeof(MsgObj), NUMMSGS, &mbxParams, NULL);
    mbxHandle = Mailbox_handle(&mbxStruct);

    MsgObj payload;
    uint8_t *ptr = NULL;

    while (true)
    {
        if(Mailbox_pend(mbxHandle, &payload, BIOS_WAIT_FOREVER))
        {
            /* System_printf("payload received: 0x%02x\r\n", payload.id); */
            ptr = payload.val;

            /* LCD_WRITE_STRING((char *)payload.val,10); */

            UART_write(hUart,ptr,strlen((char*)ptr));

            /* To display properly on terminal*/
            UART_write(hUart,"\n",1);

            System_flush();
        }
    }
}

So, I have created a task for Mail_box as shown in above code snippet and i am printing the received bytes from here by using "UART_write" which i have received in  "buff" array .

And the very same logic i tried with "uartecho" example of the sdk and it was working fine.

  • If I understand correctly, you can implement the exact same UART code in a stand-alone UART Echo example, and there it works as expected, but implementing it in the TI1-5.4 Collector example, it does not work. Is that correct?

    I will assume that this is due to the collector code has a lot of other stuff going on, and this will somehow interfere with the UART code.

    I noticed that you are calling UART_read from within the rxCallback, but I assume that you are calling it from elsewhere also?

    Please note that it is not recommended to call UART_read from its own callback as this can potentially lead to stack overflow issues. We recommend posting a semaphore from the callback function and to handle subsequent reads from within your task.

    Not able to give you any clear pointers here, as that is not possible without the complete code, so I guess you just need to debug further to see if you can figure out what exactly causes the problems.

    Have you for example tried to not do UART_write, amd just monitor your buffers using the debugger to see if everything is received as it should then?

    Have you removed all the UART_writes that are int the default example, to see if these messes things up?

    Siri

  • If I understand correctly, you can implement the exact same UART code in a stand-alone UART Echo example, and there it works as expected, but implementing it in the TI1-5.4 Collector example, it does not work. Is that correct?

    yes.

    I will assume that this is due to the collector code has a lot of other stuff going on, and this will somehow interfere with the UART code.

    Maybe that would be the case.

    I noticed that you are calling UART_read from within the rxCallback, but I assume that you are calling it from elsewhere also?

    The very first time I am calling it in  "appTaskFxn" and then onwards in rxCallback, Is there any other way to achieve the same?

    Please note that it is not recommended to call UART_read from its own callback as this can potentially lead to stack overflow issues. We recommend posting a semaphore from the callback function and to handle subsequent reads from within your task.

    Can you share any pseudo-code for the same?

    Have you for example tried to not do UART_write, amd just monitor your buffers using the debugger to see if everything is received as it should then?

    Yes, most of the time buffer is getting filled properly.

    Have you removed all the UART_writes that are int the default example, to see if these messes things up?

    Yes, I have tried that way too.

  • I guess one solution would be to have a separate task for this, as mentioned here:

    e2e.ti.com/.../ccs-launchxl-cc1310-using-uart-task-with-ti-15-4-sensor-example

  • Please note that it is not recommended to call UART_read from its own callback as this can potentially lead to stack overflow issues. We recommend posting a semaphore from the callback function and to handle subsequent reads from within your task.

    Thanks Siri, This work for me.