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.

CCS/LAUNCHXL-CC1312R1: Not able to write on UART properly

Part Number: LAUNCHXL-CC1312R1
Other Parts Discussed in Thread: TIDA-010032,

Tool/software: Code Composer Studio

Hi to all,

I'm using LAUNCHXL-CC1312R1 with library version (2.40, TIDA-010032).

In the UART write part I'm not able to write more than 8 char at a time. If I try more than 8 they will appear at the next cycle.

Uart setting are 

UART_Params params;
UART_Params_init(&params1);
params1.writeMode = UART_MODE_CALLBACK;
params1.writeDataMode = UART_DATA_BINARY;
params1.writeCallback = UartWriteCallbackM;
params1.readMode = UART_MODE_CALLBACK;
params1.readDataMode = UART_DATA_BINARY;
params1.readCallback = UartReadCallbackM;

handle = UART_open(Board_UART0, &params);
if (!handle)
{
Task_exit();
}

UART_write(handle, input, strlen(input));
UART_read(handle, gUartRxBuffer, sizeof(gUartRxBuffer));

(Note:- input is an array, char input[]="Uart write done")

I'm only able to get "UART wri" instead of the whole string. same goes with other input too.

Thanks in advance 

Sourabh Vyas

  • Hi S,

    Could you add in how you setup the callback functions in this case? Also, are you calling "write" at some other location? 

  • Hi,

    static void UartWriteCallbackM(UART_Handle _handle, void *_buf, size_t _size)
    {
    uint32_t key = HwiP_disable();
    //gUartWriteComplete = true;
    /* Exit critical section */
    HwiP_restore(key);
    }
    /*******************************************************************************
    * @fn UartReadCallbackMeter
    *
    * @brief
    *

    *******************************************************************************
    */
    static void UartReadCallbackM(UART_Handle _handle, void *_buf, size_t _size)
    {
    // Make sure we received all expected bytes
    if (_size)
    {
    // If cleared, then read it
    // dataRcv=1;
    for(size_t i = 0; i < _size; i++)
    {
    gUartRxBufferM[dataRcv++] = ((uint8_t*)_buf)[i];

    }

    memset(_buf, '\0', _size);
    if(dataRcv==150)
    dataRcv=0;

    UART_read(handle gUartTxBuffer, _size);
    }
    else
    {
    // Handle error or call to UART_readCancel()
    UART_readCancel(handle );
    }
    }

    This is both a callback function.

    I'm calling UART_Write whenever I receive anything on the RF.

    Thanks and regards

    Sourabh Vyas

  • Could you show the RF part as well? As for the write, is the callback invoked? What is the returned size in that case?

  • Sorry for late reply sir,

    This is Uart write call in RF area

    udp_event_handler(udp_context_t *ctx)
    {
    char *appdata;
    #if (POLL_APP)
    udp_address_t remote;
    #endif

    //copy received data, size, and seqNo
    appdata=&(appRxFifo[appRxFifo_ReadIdx].c[UIP_IPUDPH_LEN + UIP_LLH_LEN]);
    //parse seqno and size (based on application data format in simple-udp-meter.h)
    //memcpy(&rcvd_seqno, appdata, sizeof(rcvd_seqno));
    //memcpy(&rcvd_size, appdata + sizeof(rcvd_seqno), sizeof(rcvd_size));

    memcpy(&rcvd_seqno, appdata+1, sizeof(rcvd_seqno));
    memcpy(&rcvd_size, appdata +1+ sizeof(rcvd_seqno), sizeof(rcvd_size));
    memcpy(&type, appdata, sizeof(type));

    /******************Poll request to device***************************************/
    memset(gUartTxBufferMeter,'\0',150);
    dataRcv=datalenrxtx=0;
    if(*(appdata+6)==0x7E)
    {
    datalenrxtx = 2 + *(appdata+8);
    memcpy(gUartTxBufferM,appdata+6,datalenrxtx+1);
    }

    //memcpy(gUartTxBufferMeter,appdata+8,150);
    UART_write(gUartHandleM, gUartTxBufferM,datalenrxtx);
    TS3 = clock_seconds();
    dataRcv=datalenrxtx=0;
    UART_read(gUartHandleM gUartRxBuffer, 10);

    /*********************************************************/

    #if (POLL_APP)
    //parse src address
    uip_ipaddr_copy(&remote.addr, &APP_UIP_IP_BUF->srcipaddr);
    remote.port = APP_UIP_UDP_BUF->srcport;

    sample_udp_echoback(ctx, &remote, pudp_msg); /*Resp from meter and send to RF*/
    #endif

    }

    So whatever data I'm getting in the RF from the head system I'm giving to my device on UART and result I'm reading from UART and passing that result to the head system over RF.

    After every UART write call Uart handler is calling but some data is not writing to UART as I explain to my earlier comments.

    Thanks 

    Sourabh Vyas

  • Hi S,

    You do not seem to guard against "clobbering" writes? While this would be prevented by the driver, it seems liek you could be overwriting the buffer content before it might have been sent out?