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.

CC3200SDK: UART Read CALL - Back functionality

Part Number: CC3200SDK

Hi,

I am trying to find an example with UART reading by callback functionality. Was read ever tested by setting it readMode = UART_MODE_CALLBACK? 

I followed into the driver code in UARTCC32XX.c ...

The UARTCC32XX_Object -> state -> 

 struct {
        bool             opened:1;         /* Has the obj been opened */
        UART_Mode        readMode:1;       /* Mode for all read calls */
        UART_Mode        writeMode:1;      /* Mode for all write calls */
        UART_DataMode    readDataMode:1;   /* Type of data being read */
        UART_DataMode    writeDataMode:1;  /* Type of data being written */
        UART_ReturnMode  readReturnMode:1; /* Receive return mode */
        UART_Echo        readEcho:1;       /* Echo received data back */
        /*
    } state;

These are saved as a bool type I believe, and when its being compared in function UARTCC32XX_read .. in line 583

if ((object->state.readMode == UART_MODE_CALLBACK) && object->readSize) ... the first statement object->state.readMode == UART_MODE_CALLBACK is evaluating to 0 rather than 1. As -1 != 1.

I put a break point in the function readIsrBinaryCallback, and the program never stops there. 

SimpleLink CC32xx SDK (3.10.00.04) is Installed. Bellow is the code I am trying to run. Never get any call back from the UART. 

#define MAX_STR_SIZE 256
pthread_mutex_t scanMutex;
UART_Handle uartHandle;
char pcBuffer[MAX_STR_SIZE] = "";

void Initialize(){// Default settings
        UART_Params uartParams;
        UART_Params_init(&uartParams);
        uartParams.readMode = UART_MODE_CALLBACK;
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_NEWLINE;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 115200;
        uartParams.readCallback = ReadCallback_fxn;
        
        UART_init();

        uartHandle = UART_open(uartPort, &uartParams);
        /* remove UART receive from LPDS dependency */
        UART_control(uartHandle, UART_CMD_RXDISABLE, NULL);
        
        int retc;
        retc = pthread_mutex_init(&scanMutex, NULL);
        if (retc != 0) {
           /* pthread_mutex_init() failed */
           //TODO
        }
}

void main_thread( void )
{
    int retc;
    size_t pcBufflen;

    char scanBuffer[MAX_STR_SIZE];
    retc = UART_read(uartHandle, scanBuffer, MAX_STR_SIZE);
    if (retc == -1)
    {
        Log("Scan UART Error!");
    }

    while(true)
    {
        pthread_mutex_lock(&scanMutex);
        pcBufflen = strlen(pcBuffer);

        if(pcBufflen > 0)
        {
            scanQueue.send(pcBuffer, pcBufflen);

            memset((void*)pcBuffer, 0, MAX_STR_SIZE);

            pthread_mutex_unlock(&scanMutex);

            retc = UART_read(uartHandle, scanBuffer, MAX_STR_SIZE);

            if (retc == -1)
            {
                Log("Scan UART Error!");
            }
        }
        else
        {
            pthread_mutex_unlock(&scanMutex);
            Thread::sleep(0.5);
        }
    }
}

void ReadCallback_fxn( UART_Handle handle, void *buf, size_t count )
{
    if( count < MAX_STR_SIZE)
    {
        pthread_mutex_lock(&scanMutex);
        strncpy(pcBuffer, (char*)buf, count);
        pthread_mutex_unlock(&scanMutex);
    }
    else
    {
        Log("Scanned %d chars longer than Max - %d chars!", MAX_STR_SIZE, count);
    };
}

Any help would be great thanks. 

  • Tashfique,

    Are you sending a new line character so that the return function returns? IF you change this to binary, do you still have the issue?

    BR,

    Vince

  • So I was calling Control function and thats what was causing the problems. Its working perfectly fine now!

    Just had to remove this line.

    /* remove UART receive from LPDS dependency */
            UART_control(uartHandle, UART_CMD_RXDISABLE, NULL);
    I still think there is a bug in the driver code.

    UARTCC32XX_read .. in line 583

    if ((object->state.readMode == UART_MODE_CALLBACK) && object->readSize) ... the first statement object->state.readMode == UART_MODE_CALLBACK is evaluating to 0 rather than 1. As -1 != 1.

    Chow.