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/CC3220SF: UART CALLBACK (I cannot read)

Part Number: CC3220SF
Other Parts Discussed in Thread: SYSBIOS

Tool/software: Code Composer Studio

Hi,

I use "CC3220SF LAUNCHXL" Board. I run below code and at initial I got only "UART Callback Test" message from UART. But unfortunately my readcallback function doesn't run. I couldn't initialized the readcallback. What is the problem at my code? Could you please check and help me?

/*
* ======== uartecho.c ========
*/
#include <stdint.h>
#include <stddef.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>

/* Example/Board Header files */
#include "SKB_Board.h"

#define MAX_NUM_RX_BYTES 1000 // Maximum RX bytes to receive in one go
#define MAX_NUM_TX_BYTES 1000 // Maximum TX bytes to send in one go

const char test_message[] = "UART Callback Test:\r\n";
uint32_t wantedRxBytes; // Number of bytes received so far
uint8_t rxBuf[MAX_NUM_RX_BYTES]; // Receive buffer
uint8_t txBuf[MAX_NUM_TX_BYTES]; // Transmit buffer

static void readCallback(UART_Handle handle, void *rxBuf, size_t size);
static void writeCallback(UART_Handle handle, void *rxBuf, size_t size);

/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
UART_Handle handle;
UART_Params params;

/* Call driver init functions */
GPIO_init();

/* Configure the LED pin */
GPIO_setConfig(Output1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Turn on user LED */
GPIO_write(Output1, CC3220SF_GPIO_ON);

// Init UART
UART_init();
// Specify non-default parameters
UART_Params_init(&params);
params.baudRate = 115200;
params.writeMode = UART_MODE_CALLBACK;
params.writeDataMode = UART_DATA_BINARY;
params.writeCallback = writeCallback;
params.readMode = UART_MODE_CALLBACK;
params.readDataMode = UART_DATA_BINARY;
params.readCallback = readCallback;

handle = UART_open(DEBUG_UART, &params);
//uart1 = UART_open(IMU_UART, &uartParams);

if (handle == NULL) {
/* UART_open() failed */
while (1);
}

UART_write(handle, test_message, sizeof(test_message));
//UART_write(uart1, echoPrompt, sizeof(echoPrompt));

wantedRxBytes = 16;
int rxBytes = UART_read(handle, rxBuf, wantedRxBytes);
while(1); // Wait forever
}

// Read callback function
static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
uint8_t i=0;

GPIO_toggle(Output1);
// Make sure we received all expected bytes
if (size == wantedRxBytes) {
// Copy bytes from RX buffer to TX buffer
for(i = 0; i < size; i++)
txBuf[i] = ((uint8_t*)rxBuf)[i];
// Echo the bytes received back to transmitter
UART_write(handle, txBuf, size);
// Start another read, with size the same as it was during first call to
// UART_read()
UART_read(handle, rxBuf, wantedRxBytes);
}
else {
// Handle error or call to UART_readCancel()
}
}
// Write callback function
static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
// Do nothing
}

  • Hi Kemal,

    You are not able to call a UART function from within a driver callback. Can you try removing the UART commands and see if the behavior changes?

    Best regards,

    Sarah

  • Hi,

    I removed all UART functions in Callback function. Only GPIO_Toggle function is available But unfortunately Callback function wasn't activated with this way. My update code:

    /*
    * ======== uartecho.c ========
    */
    #include <stdint.h>
    #include <stddef.h>

    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>

    /* Example/Board Header files */
    #include "SKB_Board.h"

    #define MAX_NUM_RX_BYTES 1000 // Maximum RX bytes to receive in one go
    #define MAX_NUM_TX_BYTES 1000 // Maximum TX bytes to send in one go

    const char test_message[] = "UART Callback Test:\r\n";
    uint32_t wantedRxBytes; // Number of bytes received so far
    uint8_t rxBuf[MAX_NUM_RX_BYTES]; // Receive buffer
    uint8_t txBuf[MAX_NUM_TX_BYTES]; // Transmit buffer

    static void readCallback(UART_Handle handle, void *rxBuf, size_t size);
    static void writeCallback(UART_Handle handle, void *rxBuf, size_t size);

    /*
    * ======== mainThread ========
    */
    void *mainThread(void *arg0)
    {
    UART_Handle handle;
    UART_Params params;

    /* Call driver init functions */
    GPIO_init();

    /* Configure the LED pin */
    GPIO_setConfig(Output1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    /* Turn on user LED */
    GPIO_write(Output1, CC3220SF_GPIO_ON);

    // Init UART
    UART_init();
    // Specify non-default parameters
    UART_Params_init(&params);
    params.baudRate = 115200;
    params.writeMode = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode = UART_MODE_CALLBACK;
    params.readDataMode = UART_DATA_BINARY;
    params.readCallback = readCallback;

    handle = UART_open(DEBUG_UART, &params);
    //uart1 = UART_open(IMU_UART, &uartParams);

    if (handle == NULL) {
    /* UART_open() failed */
    while (1);
    }

    UART_write(handle, test_message, sizeof(test_message));
    //UART_write(uart1, echoPrompt, sizeof(echoPrompt));

    wantedRxBytes = 16;
    int rxBytes = UART_read(handle, rxBuf, wantedRxBytes);
    while(1); // Wait forever
    }

    // Read callback function
    static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
    {
    uint8_t i=0;

    GPIO_toggle(Output1);
    }


    // Write callback function
    static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
    {
    // Do nothing
    }

  • Hi Kemal,

    Can you make your UART_read call for a single byte and a smaller buffer? We want to verify you are receiving enough data to trigger the callback. Please also place a breakpoint at the entry of the callback.

    Best regards,

    Sarah

  • Hi,

    Could you please show it with a small code block? I think As TI, you should provide Uart_callback(interrupt) code in examples but it is not available inside driver or sysbios examples. Could you please help us providing me running code block?

    Thanks.

  • Hi Kemal,

    We have test code that is implemented the same way you have done, which is why I'm trying to verify that you are receiving any UART data and determine if you are entering the callback. Can you please try those steps?

    Best regards,

    Sarah