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: CC1310: UART interrupt using Callback Api's

Part Number: CC1310
Other Parts Discussed in Thread: CC1312R,

Dear,

i am using CC1312R launchpad ,CCS v10 and simplelink_cc13x2_26x2_sdk_4_10_00_78/kernel/tirtos/packages.

I am trying to setup a uart commnad link with my IOT device and print out the debug message to PC.

I am new to the this dev system  and have some question to ask about , my works is on some reference from the echo example and some source from this forum .

1) For the UART CALLBACK listed in

typedef void(* UART_Callback) (UART_Handle, void *buf, size_t count),  does it mean it will ONLY goto callback when it the UART received COUNT byte ?

2) for the return mode,

UART operationUART_RETURN_FULLUART_RETURN_NEWLINE
UART_read() Returns when buffer is full Returns when buffer is full or newline was read

so in case i use uart_return_newline , does it mean it will goto callback when buffer is full or newline was read?

3) and so

Receive with Return Partial

This use case will read in UART_MODE_BLOCKING until the wanted amount of bytes is received or until a started reception is inactive for a 32-bit period. This UART_read() call can also be used when unknown amount of bytes shall be read. Note: The partial return is also possible in UART_MODE_CALLBACK mode.

whats the main usage of that ?

I want to use this because my IOT device sometimes return unknown amount of byte, but this question is related to (1) and (2)

4)  my code was based on the driver page , and was listed as below

/*
 * Copyright (c) 2015-2017, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

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

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

/* Example/Board Header files */
//#include "Board.h"
UART_Handle uart;
UART_Handle uart2;
UART_Params uartParams,uartParams1;


    //Receive Continously in UART_MODE_CALLBACK

//This case will configure the UART to receive and transmit continously in UART_MODE_CALLBACK, 16 bytes at the time and transmit them back via UART TX. Note that UART_Params.readTimeout is not in use when using UART_MODE_CALLBACK mode.

char        input[100];
uint8_t     uartLineEndCount = 0;
#define MAX_NUM_RX_BYTES    100   // Maximum RX bytes to receive in one go
#define MAX_NUM_TX_BYTES    100   // Maximum TX bytes to send in one go
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
char cmd_string[64];
unsigned char received = 0;
unsigned char test_cnt = 0;

void bc_28_init(void);

void Uart2_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
   // UART_read(uart, &input, 1);
   // uartLineEndCount++;
   // UART_write(uart, input, 1);
}
void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    unsigned int i;
    if (size == wantedRxBytes) {
        // Copy bytes from RX buffer to TX buffer
        for(i = 0; i < size; i++)
        {
            txBuf[i] = ((uint8_t*)rxBuf)[i];
           // test_cnt++;
        }
       // Echo the bytes received back to transmitter
     //  UART_write(uart2, rxBuf, 1); //
        received = 1;
        UART_read(uart, 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
}
/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{


    const char  echoPrompt[] = "Echoing characters:\r\n";
    /* Call driver init functions */
    GPIO_init();
    UART_init();

    /* Configure the LED pin */
    //GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* Turn on user LED */
    //GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
//================
//UART0 for BC28
    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = Uart_ReadCallback;
    uartParams.writeDataMode = UART_DATA_TEXT;
    uartParams.readDataMode = UART_DATA_TEXT;
    uartParams.readReturnMode = UART_RETURN_NEWLINE;//UART_RETURN_FULL;//UART_RETURN_NEWLINE;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;
//================
    uart = UART_open(CONFIG_UART_0, &uartParams);
//================
//UART1 for DEBUG
    UART_Params_init(&uartParams1);
    uartParams1.readMode = UART_MODE_CALLBACK;
    uartParams1.readCallback = Uart2_ReadCallback;
    uartParams1.writeDataMode = UART_DATA_TEXT;// text mode = processed , binrary is unprocess
    uartParams1.readDataMode = UART_DATA_TEXT;
    uartParams1.readReturnMode = UART_RETURN_NEWLINE;
    uartParams1.readEcho = UART_ECHO_OFF;
    uartParams1.baudRate = 9600;

    uart2 = UART_open(CONFIG_UART_1, &uartParams1);

//================
    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    UART_write(uart2, echoPrompt, sizeof(echoPrompt));
    if (uart == NULL) {
        /* UART_open() failed */
        while (1);
    }

    /* Loop forever echoing */
//     UART_read(uart, &input, 1);
     wantedRxBytes = 52; //desire number of byte to get
     int rxBytes = UART_read(uart, rxBuf, wantedRxBytes);
     //int rxBytes2 = UART_read(uart2, rxBuf, wantedRxBytes);
     bc_init();
     while (1)
     {
//         memset(cmd_string, 0, sizeof(cmd_string))//;
//         sprintf(cmd_string,"ABC",0);
//         UART_write(uart2,cmd_string,strlen(cmd_string));
         if(received == 1)
         {
             UART_write(uart2, txBuf, wantedRxBytes);
                      //sprintf(cmd_string,"ABC",0);
                      //UART_write(uart2,cmd_string,strlen(cmd_string));
                      received = 0;
         }
     }
}
/*
 * uart_call_back_2.c
 *
 *  Created on: May 4, 2020
 *      Author: Admin
 */

/*
 * .c
 *
 *  Created on: May 5, 2020
 *      Author: Admin
 */


/*
bc28 work for NBIOT link
CC1312R UART

UART0

DIO 04 -- TX
DIO 05 -- RX

UART1

DIO 18 -- TX
DIO 19 -- RX


*/
const char  AT[] = "ATI\r\n";

//const char  ATI[] = "ATI\r\n";

void bc_init(void)
{
    UART_write(uart, AT, sizeof(AT));
    //UART_write(uart, ATI, sizeof(ATI));

}
/*
 * useful ? from ti forum
time = Clock_getTicks();
    memset(dumbuf,0,sizeof(dumbuf));
    sprintf(txBuf,"System time in clk0Fxn = %lu\n\r",time);
    UART_write(uart,dumbuf,strlen(dumbuf));
    //System_printf("System time in clk0Fxn = %lu\n", (ULong)time);

*/
//useful reference
//e2e.ti.com/.../3195567

my question to the above was , in the code i was assumed i know the received byte and it works fine,

but what if i didnt know the number of byte received?

thanks

Jeff

  • Hello Jeff,

    1) When the read or write finishes, the UART driver will call the user's callback function. In some cases, the UART data transfer may have been canceled, or a newline may have been received, so the number of bytes sent/received are passed to the callback function.

    2) Yes.

    3) & 4)  I will check.

    The driver is explained in the API guide:

    http://dev.ti.com/tirex/explore/node?node=AOng5xFsavzvQ16.KytQHg__eCfARaV__LATEST

  • Adding in:

    1) The drivers in this case do not support the "new line" option, it is always return full / binary mode (in other words, it does not matter what you put in the readDataMode field).

    2) See 1)

    3) When not using return partial, you will only get the callback once the given number of bytes has been received OR if there was a error detected (as this leads to the operation being canceled). Return partial is useful as it allows you to receive an unknown number of bytes. Say you know your IOT device sends at most 200 bytes, then you can say that you expect up to 200 bytes and still get a callback if only receiving 50 bytes. 

    4) If you know the actual number of bytes (but the max), then enable return partial and handle it in software:

    UART_control(handle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);

  • HI M-W,

    may i ask why "The drivers in this case do not support the "new line" option, it is always return full / binary mode (in other words, it does not matter what you put in the readDataMode field)."

    coz according to follow:

    UART return mode settings.

    This enumeration defines the return modes for UART_read() and UART_readPolling(). This mode only functions when in UART_DATA_TEXT mode.

    UART_RETURN_FULL unblocks or performs a callback when the read buffer has been filled. UART_RETURN_NEWLINE unblocks or performs a callback whenever a newline character has been received.

    UART operationUART_RETURN_FULLUART_RETURN_NEWLINE
    UART_read Returns when buffer is full Returns when buffer is full or newline was read
    UART_write Sends data as is Sends data with an additional newline at the end
      /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.readMode = UART_MODE_CALLBACK;
        uartParams.readCallback = Uart_ReadCallback;
        uartParams.writeDataMode = UART_DATA_TEXT;
        uartParams.readDataMode = UART_DATA_TEXT;
        uartParams.readReturnMode = UART_RETURN_NEWLINE;//UART_RETURN_FULL;//UART_RETURN_NEWLINE;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 9600;
    //================
        uart = UART_open(CONFIG_UART_0, &uartParams);

    whats the factor ?

    thanks

    Jeff

  • Hi Jeff,

    First of all, you are not referencing the up-to-date documentation:

    http://dev.ti.com/tirex/explore/content/simplelink_cc13x0_sdk_3_20_00_23/docs/tidrivers/doxygen/html/_u_a_r_t_8h.html

    Seems like you are getting your documentation from the "Standalone TI-RTOS" installation. If you are using this you should change to the http://www.ti.com/tool/SIMPLELINK-CC13X0-SDK as this is the only SDK actually supported by CC1310 (and it includes a fitting TI-RTOS kernel).

    You then need to take into account that the top-level header files, such as UART.h is shared across the whole SimpleLink family. This means there is device specific differences in which set of features that is supported. You should always consult the device specific header file for this information:

    http://dev.ti.com/tirex/explore/content/simplelink_cc13x0_sdk_3_20_00_23/docs/tidrivers/doxygen/html/_u_a_r_t_c_c26_x_x_8h.html

    In the end of the day, what this means is that you always have the return mode "FULL" as long as you do not enable partial read.