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.

CC2650STK: UART CallBack mode

Part Number: CC2650STK


Hi, i need help with UART. 

UART_write() performs every 1 second by the timer. UART_read() in CallBack mode and it's triggering after each UART_write(), I don't understand why.
UART_read() must work independently from UART_write(). 

I tried using different arrays for reading and writing, it did't work.

Any help is appreciated. 

void some_func()
{

}

void readCallback(UART_Handle Uhandle, void *rxBuf, size_t size)
 {
    Event_post(eventH, UART_RX_COMPLETE);
 }

void clock_cb(UArg arg)
{
    Event_post(eventH, TIMER);
}

void taskFxn(UArg arg0, UArg arg1)
{
    eventH = Event_create(NULL, NULL);

    UART_Params_init(&Uparams);
    Uparams.writeDataMode  = UART_DATA_TEXT;
    Uparams.readDataMode  = UART_DATA_TEXT;
    Uparams.readMode          = UART_MODE_CALLBACK;
    Uparams.readEcho           = UART_ECHO_OFF;
    Uparams.readCallback      = readCallback;
    Uparams.baudRate           = 9600;
    Uhandle = UART_open(0, &Uparams);
    UART_control(Uhandle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);

    UART_read(Uhandle, buff, 10);


    Clock_Params_init(&clockParams);
    clockParams.arg = (UArg)eventH;
    clockParams.startFlag = 0;
    clockH = Clock_create((Clock_FuncPtr) &clock_cb, 100000, &clockParams, NULL);
    Clock_start(clockH);


    uint8_t counter = 0x0;
    uint16_t events;

    while(true)
    {
        events = Event_pend(eventH, Event_Id_NONE, 0xFFFFFFFF, BIOS_WAIT_FOREVER);

        if (events & UART_RX_COMPLETE)
        {
            some_func();
            Task_sleep (10000);
            UART_read(Uhandle, buff, 10);
        }

        if (events & TIMER)
        {
            counter++;
            buff[0] = counter;

            UART_write(Uhandle, buff, 1);
            Task_sleep (10000);
            Clock_start (clockH);
        }

    }
}

Kind Regards, Egor

  • Hi Egor,

    Could you elaborate on " I don't understand why.
    UART_read() must work independently from UART_write()". What is the issue you have more exactly, is it that you want to use the same buffer for both write and read?

    Write and read is two, asynchronous, operations, they do not depend on each other thus they work independently. If you need them to work in sync with each other, this is implemented by synchronizing them. 

  • Hi M-W,

    After each UART_write(), readCallback triggering.

    I don't want this to happen. This happens regardless of whether I use one buffer for receiving and transmitting or different buffers.

    readCallback should work only when I receive a message 

  • Hi Egor,

    As you are using return partial, there is cases where the read callback would trigger even if there was not data received. This would for example be if there was an error or receive timeout. I would recommend you pull in the UARTCC26XX.c driver source into the project and put down a break point inside UARTCC26XX_hwiIntFxn() to see if you are getting a UART error, timeout or reception. 

    I would also recommend you to scope the RX and TX signal to verify there is no connection between these.