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.

CC1350: CC1350 RF packet data print in UART

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

Hi Experts,

Currently i am working with CC1350, i want to print my rf packet data in UART, then  i want to static UART write function to write the data in UART from all tasks.. kindly guide me to solve this task..

regards

Surya

  • Hi Surya,

    I'm not sure I completely understand what you are trying to do. Could you please provide more details on what you are trying to achieve using UART and what are the difficulties you are encountering? So I can better assist you. 

    Regards,

    Fausto

  • Hi

    Thanks for the quick response, i want to print the RF packet data through UART, then if i create any other task like interrupt counter i want to use same UART print function statically. i hope you understand my problem..

    regards

    surya

  • Do you intend to use this for debug? If so, remember that printing to UART takes 1 - 2 ms minimum and can easily block other tasks. 

    It could be that it exist a better example in the newest SDK but you can use the concept shown in the zip file posted here: https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/636545/rtos-launchxl-cc1310-cc1310-transmit-and-receive-to-rf-from-spi-or-uart Meaning that you use one task for all printing and data is passed to this task. 

  • Yes, you are correct, here i have attached my example code for your reference, here i have used Display_printf function but that is not working that's why i want to use UART write function

    /*
    * Copyright (c) 2017-2019, 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.
    */
    /*
    * ======== nvsinternal.c ========
    */

    #include <string.h>
    #include <stdlib.h>
    #include <stdint.h>

    /* Driver Header files */
    #include <ti/display/Display.h>
    #include <ti/drivers/NVS.h>

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

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

    #define FOOTER "=================================================="

    /* Buffer placed in RAM to hold bytes read from non-volatile storage. */
    static char buffer[64];
    int COUNT=0;
    /*
    * Some devices have a minimum FLASH write size of 4-bytes (1 word). Trying
    * to write a non-multiple of 4 amount of data will fail. This array is
    * rounded up (to next multiple of 4) to meet this requirement. Refer to NVS
    * driver documentation for more details.
    */
    static const char signature[52] =
    {"SimpleLink SDK Non-Volatile Storage (NVS) Example."};

    /*
    * ======== gpioButtonFxn0 ========
    * Callback function for the GPIO interrupt on Board_GPIO_BUTTON0.
    */
    void gpioButtonFxn0(uint_least8_t index)
    {
    Display_Params params;
    Display_Params_init(&params);
    params.lineClearMode = DISPLAY_CLEAR_BOTH;
    Display_Handle displayHandle = Display_open(Display_Type_UART, &params);
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_GPIO_LED0);
    COUNT++;
    Display_printf(displayHandle, 0, 0, "KEY1=%d", COUNT);
    Display_close(displayHandle);
    }

    /*
    * ======== gpioButtonFxn1 ========
    * Callback function for the GPIO interrupt on Board_GPIO_BUTTON1.
    * This may not be used for all boards.
    */
    void gpioButtonFxn1(uint_least8_t index)
    {
    Display_Params params;
    Display_Params_init(&params);
    params.lineClearMode = DISPLAY_CLEAR_BOTH;
    Display_Handle displayHandle = Display_open(Display_Type_UART, &params);
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_GPIO_LED1);
    COUNT++;
    Display_printf(displayHandle, 0, 0, "KEY2=%d", COUNT);
    Display_close(displayHandle);
    }

    /*
    * ======== mainThread ========
    */
    void *mainThread(void *arg0)
    {
    NVS_Handle nvsHandle;
    NVS_Attrs regionAttrs;
    NVS_Params nvsParams;

    Display_Handle displayHandle;

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

    /* Configure the LED and button pins */
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(Board_GPIO_BUTTON0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);

    /* Turn on user LED */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);

    /* install Button callback */
    GPIO_setCallback(Board_GPIO_BUTTON0, gpioButtonFxn0);

    /* Enable interrupts */
    GPIO_enableInt(Board_GPIO_BUTTON0);

    /*
    * If more than one input pin is available for your device, interrupts
    * will be enabled on Board_GPIO_BUTTON1.
    */
    if (Board_GPIO_BUTTON0 != Board_GPIO_BUTTON1) {
    /* Configure BUTTON1 pin */
    GPIO_setConfig(Board_GPIO_BUTTON1, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);

    /* Install Button callback */
    GPIO_setCallback(Board_GPIO_BUTTON1, gpioButtonFxn1);
    GPIO_enableInt(Board_GPIO_BUTTON1);
    }

    Display_init();
    NVS_init();

    displayHandle = Display_open(Display_Type_UART, NULL);
    if (displayHandle == NULL) {
    /* Display_open() failed */
    while (1);
    }

    NVS_Params_init(&nvsParams);
    nvsHandle = NVS_open(Board_NVSINTERNAL, &nvsParams);

    if (nvsHandle == NULL) {
    Display_printf(displayHandle, 0, 0, "NVS_open() failed.");

    return (NULL);
    }

    Display_printf(displayHandle, 0, 0, "\n");

    /*
    * This will populate a NVS_Attrs structure with properties specific
    * to a NVS_Handle such as region base address, region size,
    * and sector size.
    */
    NVS_getAttrs(nvsHandle, &regionAttrs);

    /* Display the NVS region attributes */
    Display_printf(displayHandle, 0, 0, "Region Base Address: 0x%x",
    regionAttrs.regionBase);
    Display_printf(displayHandle, 0, 0, "Sector Size: 0x%x",
    regionAttrs.sectorSize);
    Display_printf(displayHandle, 0, 0, "Region Size: 0x%x\n",
    regionAttrs.regionSize);


    /*
    * Copy "sizeof(signature)" bytes from the NVS region base address into
    * buffer. An offset of 0 specifies the offset from region base address.
    * Therefore, the bytes are copied from regionAttrs.regionBase.
    */
    NVS_read(nvsHandle, 0, (void *) buffer, sizeof(signature));

    /*
    * Determine if the NVS region contains the signature string.
    * Compare the string with the contents copied into buffer.
    */
    if (strcmp((char *) buffer, (char *) signature) == 0) {

    /* Write signature directly from the NVS region to the UART console. */
    Display_printf(displayHandle, 0, 0, "%s", regionAttrs.regionBase);
    Display_printf(displayHandle, 0, 0, "Erasing flash sector...");

    /* Erase the entire flash sector. */
    NVS_erase(nvsHandle, 0, regionAttrs.sectorSize);
    }
    else {

    /* The signature was not found in the NVS region. */
    Display_printf(displayHandle, 0, 0, "Writing signature to flash...");

    /* Write signature to memory. The flash sector is erased prior
    * to performing the write operation. This is specified by
    * NVS_WRITE_ERASE.
    */
    NVS_write(nvsHandle, 0, (void *) signature, sizeof(signature),
    NVS_WRITE_ERASE | NVS_WRITE_POST_VERIFY);
    }

    Display_printf(displayHandle, 0, 0, "Reset the device.");
    Display_printf(displayHandle, 0, 0, FOOTER);
    Display_close(displayHandle);

    return (NULL);
    }

    regards

    surya

  • Display_printf uses the UART. 

  • yes, but in above code interrupt is working fine but that count value is not printed to UART..

  • Hi Surya,

    You should check that the displayHandle returned by Display_open() is valid and not NULL. If you try printing using a NULL handle the Display_printf will not print anything to the UART line.

    You might receive a NULL handle in the case that opening a second Display instance is not allowed (as you already have an open Display instance inside your mainThread).

    Regards,

    Fausto

  • Hi

    Ok kindly let me know what changes i need to do in my code..

    regards

    Surya

  • Hi

    Sorry, In my code the main task data's are printed in UART successfully but that is not working on Button call back(gpioButtonFxn0) functions..

    regards

    Surya

  • As I said above, try verifying in your two interrupt handlers that the returned displayHandle is different than NULL. You are likely receiving a NULL because you are opening multiple Display UART instances at the same time (the first in the mainThread and an additional one inside the interrupt handlers), and this is not allowed.

    If you are receiving a NULL handle, then the scenario above is what is happening on your example. 

    You could move your displayHandle variable outside mainThread and use it as global from both the mainThread and your interrupt. However, printing over UART from an interrupt handler is highly discouraged, because of the latency associated with it, and could lead to task being blocked for a very long time. I suggest you follow the example linked by TheGhostOf and use a separate thread to perform all the UART printing.

    Regards,

    Fausto

  • Hi

    Ok i agree with your suggestion about print used in interrupt handler, now i am just testing the printf function working in other tasks or not..

    then i have checked suggested code, that is have UART print function only on RFpacket received function only, here i am trying to create a function like serialprint(("HELLO=%d",COUNT); or serialprint(("TASK OK") this will use any thread main or created sub threads..

    regards

    surya

  • Surya: A question on the side: Why are you using CC1350? If you are planning to use only one band, look at CC1310/ CC1312R. If you want to include BLE, use CC1352R etc to get sufficient memory to run two stacks. 

  • Hi

    Thanks for your clarification, then we have an OTA plan in future so we use CC1350 to our project that will make very familiar to CC1350..

    regards

    surya

  • Hi Surya,

    do you have any update on your status? Let me know if you need further assistance or if I can close the thread. 

    Regards,

    Fausto

  • Hi 

    Thanks for the reply, i have stopped development with cc1350 then now i bought cc1312 launchpad for development here i need your advice for below requirements..

    1. 1.i want read the interrupt count and store that count in NVS read at same time,
    2. Send that count and Adc value through RF packet
    3. Print ADC value and interrupt count to UART

    Here how can i do that, which example is suitable for this work..

    Those data's transmitted based on interval other time the RF part want to shutdown..

    There is any option for change the frequency for avoiding the data collision..

    Regards

    Surya

  • Hi Surya, 

    I apologize for the late reply. 

    - If you are using RF in your application, I suggest you start with the two examples rfPacketTx and rxPacketTx. Get comfortable with how they function and then you can integrate inside of them the UART and NVS functionalities. To start working with the UART2 and NVS drivers I suggest you have a look at examples uart2echo/uart2callback and nvsinternal/nvsexternal that should help you understand how to interact with the two peripherals through TI drivers. 

    - If you want to to make small frequency adjustment within the same band at run-time, you can do this with an CMD_FS frequency (RF_cmdFs.frequency in rfPacket examples -> more details in this related thread https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/897167/cc1312r-frequency-change-related-questions . 

    If you are instead looking to do bigger jumps in frequency I believe you will have to power off the RF core and issue a new setup command with a different center frequency (RF_cmdPropRadioDivSetup.centerFreq in rfPacket examples).

    Regards,

    Fausto

  • Hi

    Thanks for the reply, i will check and let us know..

    regards

    Surya

  • Sure Surya. Please update the thread once the case is resolved or if you have more questions.

    Regards,

    Fausto