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.

cc1310: UART_write cannot write all the data success and partial of data will lost

Other Parts Discussed in Thread: CC1310

Hi everyone:

          I realised that the uart of cc1310 is too nauty to control (may be it is just beacuse I am not smart enough(ू˃̣̣̣̣̣̣︿˂̣̣̣̣̣̣ ू)  )  I am tired to find why the uart struct  the tast,  why the uart cannot read all the data but partial from the pc and so on (those problem have been solved), and now a new problem puzzles me: I find that the  UART_write cannot write what I want totally success but partial of them is abandoned by it.

Follow is my code of uart processing:

#define UART_ONCE_MAX_LEN 512
void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
        UartFifo_push_str(&Uart_ReceiveFiFo, (uint8_t *)rxBuf, (uint16_t)size);
        UART_read(handle, Uart_RxTempBuf, UART_ONCE_MAX_LEN);
        Event_post(uartEventHandle, UART_EVENT_RECEIVED);
}

void Uart_WriteCallback(UART_Handle handle, void *txBuf, size_t size)
{
        UART_read(handle, Uart_RxTempBuf, UART_ONCE_MAX_LEN);
}

Void UartTaskFunction(UArg arg0, UArg arg1)
{
        UART_Params uartParams;
        UART_Params_init(&uartParams);
        uartParams.readMode = UART_MODE_CALLBACK;
        uartParams.readCallback = Uart_ReadCallback;
        uartParams.writeCallback = Uart_WriteCallback;
        uartParams.writeMode = UART_MODE_CALLBACK;
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_FULL;
        // uartParams.readTimeout = (10000 / Clock_tickPeriod);
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 115200;
        uartHdl = UART_open(Board_UART0, &uartParams);

        if (uartHdl == NULL) {
                System_abort("Error opening the UART");
        }
        UART_control(uartHdl, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);
        UART_read(uartHdl, Uart_RxTempBuf, UART_ONCE_MAX_LEN);
        UART_write(uartHdl, "\r\nJust for a test......\r\n", 25);

        while (1)
        {
                uint32_t events = Event_pend(uartEventHandle, 0, UART_EVENT_ALL, BIOS_WAIT_FOREVER);

                if(events & UART_EVENT_PRINT)
                {
                        if(Uart_TransmitFiFo.In < Uart_TransmitFiFo.Out)
                        {
                                UART_write(uartHdl, Uart_TransmitFiFo.Buf + Uart_TransmitFiFo.Out, UART_BUF_SIZE - Uart_TransmitFiFo.Out);
                                UART_write(uartHdl, Uart_TransmitFiFo.Buf,Uart_TransmitFiFo.In);
                                Uart_TransmitFiFo.Out = Uart_TransmitFiFo.In;
                       }
                        else if(Uart_TransmitFiFo.In > Uart_TransmitFiFo.Out)
                        {
                                UART_write(uartHdl, Uart_TransmitFiFo.Buf + Uart_TransmitFiFo.Out, Uart_TransmitFiFo.In - Uart_TransmitFiFo.Out);
                                Uart_TransmitFiFo.Out = Uart_TransmitFiFo.In;
                        }
                }
                if(events & UART_EVENT_RECEIVED)
                {
                        if(Uart_ReceiveFiFo.Out != Uart_ReceiveFiFo.In)
                        {
                                if(g_SystemWorkmode & RF_ENABLE)
                                        g_SystemWorkmode |= RF_NEED_TRANSMIT;
                                else
                                {
                                        if((Uart_ReceiveFiFo.Buf[Uart_ReceiveFiFo.In-1] == '\r') ||(Uart_ReceiveFiFo.Buf[Uart_ReceiveFiFo.In-1] == '\n'))//
                                        {
                                                FullUsrCommandBuf();
                                                CommandLineInterpreter(UsrCommand_buf);
                                        }
                                }
                        }
                }
        }
}

Is there any problem in my code???? what can i do to solve this problem?

  • Could this be a flow control issue? Can you try sending <16B at a time and add a delay in between the 16B Tx's? Just as a test to see if you are sending data faster than the receiver can read it?

    Regards, TC.
  • No,It doesn't work.
  • I think part of the problem is, when Uart_WriteCallback runs, that should be taken as a sign of "UART driver has written X bytes and now it's ready for more data" -- however -- that "X bytes" might not be the amount you originally intended to write (i.e. 25).

    So your Uart_WriteCallback should examine the 'size' argument being given to it and determine how much of your original data is yet to be sent, then issue another UART_write() on the remaining data, wash rinse & repeat until all the data is sent.

    Example of what I'm thinking of:

    // put this in the global
    volatile char *uartWriteData;
    volatile size_t uartWriteRemains;
    
    void Uart_WriteCallback(UART_Handle handle, void *txBuf, size_t size)
    {
      uartWriteRemains -= size;
      if (uartWriteRemains > 0) {
        // UART wasn't able to send all our data in one attempt; submit the remainder
        uartWriteData += size;  // Advance pointer
        UART_write(handle, uartWriteData, uartWriteRemains);
      } else {
        // Write request is fully complete; do whatever we need to afterwards
        UART_read(handle, Uart_RxTempBuf, UART_ONCE_MAX_LEN);
      }
    }
    
    // Meanwhile, in UartTaskFunction...
    ...

    UART_read(uartHdl, Uart_RxTempBuf, UART_ONCE_MAX_LEN);
    //UART_write(uartHdl, "\r\nJust for a test......\r\n", 25); // commenting this out, using the following 3 lines in place: uartWriteData = "\r\nJust for a test......\r\n"; uartWriteRemains = 25; UART_write(uartHdl, uartWriteData, uartWriteRemains); // Initiate UART write process
    ...

  • Hi Eric:
    I tried as you said, but it seems no improvement. I am really annoyed that I can recevied the packets through RF core and decode successfull but why I cannot send the valid data successfull through UART?????