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.

CC3220SF-LAUNCHXL: Simple UART RX with TI drivers

Part Number: CC3220SF-LAUNCHXL

Hi community !

I am using no RTOS and my goal is to simply be asynchronously notified when data is received. In the "old days" I would be notified by the UART INTerrupt and handle the data from there.

Now with the UART driver, do I have to poll with UART_read() ? I have tried to set the UART_Params to callback mode but it doesn't behave as I expect.

What's the trigger condition for the callback function to be called ?

This is the code I've added / modified from the uartecho example.

void sReadCallback(UART_Handle handle, void *buf, size_t count);

uartParams.readCallback = &sReadCallback;
uartParams.readMode = UART_MODE_CALLBACK;

while (1) {
    	// UART_read(uart, &input, 1);
    	// UART_write(uart, &input, 1);
} 

void sReadCallback(UART_Handle handle, void *buf, size_t count) {
	// Never comes here !!!
        UART_write(handle, buf, count);
}

It should be easy enough, can someone show me the right way to do this before I spend more unnecessary time on this..

Thanks !

 

  • Hi Vincent,

    UART_MODE_CALLBACK means that when UART_read is complete, it will trigger the callback function passed in uartParams. What behavior are you seeing/expecting? Have you previously initialized the UART (UART_init) and its parameters (UART_Params_init(&uartParams))?

    Keep in mind we do not suggest calling a UART function within a callback. Take a look at the TI Drivers API documentation in the SDK. If you have version 1.50 installed, this would be the file path:
    file:///C:/ti/simplelink_cc32xx_sdk_1_50_00_06/docs/tidrivers/doxygen/html/_u_a_r_t_8h.html

    Best regards,
    Sarah
  • Hi Sarah,

    Yes, I am using the uartecho example. Then I simply changed the lines mentioned in my previous post to test the callback functionality.

    What is the conditions for a UART_read to be complete ?

    What I'm expecting is that when sending data to that uart, the callback function should be called without having to poll the UART_read function.

    I have read the documentation and changed some parameters (e.g. uartParams.readReturnMode to UART_RETURN_NEWLINE) but it didn't help. The callback function is never being called.

    Thanks for the help ! 

    Vincent

  • Hi Vincent,

    The callback should happen when the buffer you give UART_read() is filled, as the driver implementation monitors how many bytes you have transferred and how many are left to transfer. What are you using as your count? Have you tried decreasing the size?

    Best regards,
    Sarah
  • Alright. So we HAVE TO poll...........

    I was hoping that it was not the case and that it was possible to get "asynchronous" events.

    Second: When polling I am using the UART_readPolling(). Unfortunately it seems to be BLOCKING and does not return until data arrives (eventhough readMode is set to UART_MODE_CALLBACK)...

    Here is my code to make things clear.

    #define BUFFER_SIZE 10
    
    void sReadCallback(UART_Handle handle, void *buf, size_t count) {
    }
    
    void *mainThread(void *arg0)
    {
        char        inputBuffer[BUFFER_SIZE];
        UART_Handle uartHandle;
        UART_Params uartParams;
        int_fast32_t readBytes;
    
        /* Call driver init functions */
        UART_init();
    
        /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_TEXT;
        uartParams.readReturnMode = UART_RETURN_NEWLINE;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 115200;
        uartParams.readCallback = &sReadCallback;
        uartParams.readMode = UART_MODE_CALLBACK;
    
        uartHandle = UART_open(Board_UART0, &uartParams);
    
        if (uartHandle == NULL) {
            /* UART_open() failed */
            while (1);
        }
    
        int dummy;
    
        /* Loop forever */
        while (1) {
        	readBytes = UART_readPolling(uartHandle, &inputBuffer, BUFFER_SIZE);
        	if(readBytes > 0) 
        		dummy = readBytes;
        }
    }

    Thanks !

  • Hi Vincent,

    I'm confused as to why you think you have to poll. UART_read will trigger the callback function when it has filled the buffer provided.

    Have you used a logic analyzer on your RX line? Can you verify you are receiving data?

    Best regards,
    Sarah
  • Thanks for your time.

    By polling I mean calling UART_readPolling() continuously, as in my code snippet here above.

    Note that we are NOT using an RTOS.

    Yes data is coming on the line.