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/LAUNCHXL-CC1350: using RF and UART Example together

Part Number: LAUNCHXL-CC1350
Other Parts Discussed in Thread: CC1310, CC1350

Tool/software: Code Composer Studio

hi,

i am working with LAUNCHPAD-CC1350 and i am new in it.

i have launched the primiray examples and now i wrote my own project.

I've combined two examples(rfPacketRx and uartecho with the help of adcbufcontinuous) for getting packets and give theme to pc terminal through UART.

my program just work one time and after that it stop and doesn't work any more.

could anybody help me?

the Sending Launchpad is Working fine and this is my Receiver Side program.

/*
 * Copyright (c) 2015-2016, 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.
 */

/***** Includes *****/
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>

/* Drivers */
#include <ti/drivers/rf/RF.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>
#include <driverlib/rf_prop_mailbox.h>

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

#include "RFQueue.h"
#include "smartrf_settings/smartrf_settings.h"

#include <stdlib.h>

/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;

/*
 * Application LED pin configuration table:
 *   - All LEDs board LEDs are off.
 */
PIN_Config pinTable[] = {
    Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
};


/***** Defines *****/
#define TASK_STACK_SIZE      1024

/* Packet RX Configuration */
#define DATA_ENTRY_HEADER_SIZE 8  /* Constant header size of a Generic Data Entry */
#define MAX_LENGTH             30 /* Max length byte the radio will accept */
#define NUM_DATA_ENTRIES       2  /* NOTE: Only two data entries supported at the moment */
#define NUM_APPENDED_BYTES     2  /* The Data Entries data field will contain:
                                   * 1 Header byte (RF_cmdPropRx.rxConf.bIncludeHdr = 0x1)
                                   * Max 30 payload bytes
                                   * 1 status byte (RF_cmdPropRx.rxConf.bAppendStatus = 0x1) */

/***** Prototypes *****/
static void TaskFunction(UArg arg0, UArg arg1);

/***** Variable declarations *****/
static Task_Params TaskParams;
Task_Struct rxTask;    /* not static so you can see in ROV */
static uint8_t TaskStack[TASK_STACK_SIZE];

static RF_Object rfObject;
static RF_Handle rfHandle;

/* Buffer which contains all Data Entries for receiving data.
 * Pragmas are needed to make sure this buffer is 4 byte aligned (requirement from the RF Core) */
#if defined(__TI_COMPILER_VERSION__)
    #pragma DATA_ALIGN (rxDataEntryBuffer, 4);
        static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES,
                                                                 MAX_LENGTH,
                                                                 NUM_APPENDED_BYTES)];
#elif defined(__IAR_SYSTEMS_ICC__)
    #pragma data_alignment = 4
        static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES,
                                                                 MAX_LENGTH,
                                                                 NUM_APPENDED_BYTES)];
#elif defined(__GNUC__)
        static uint8_t rxDataEntryBuffer [RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES,
            MAX_LENGTH, NUM_APPENDED_BYTES)] __attribute__ ((aligned (4)));
#else
    #error This compiler is not supported.
#endif

/* Receive dataQueue for RF Core to fill in data */
static dataQueue_t dataQueue;
static rfc_dataEntryGeneral_t* currentDataEntry;
static uint8_t packetLength;
static uint8_t* packetDataPointer;

static uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */
uint16_t       PAYLOAD_LENGTH=0;
char           uartTxBuffer[MAX_LENGTH];

UART_Handle uart;

/***** Function definitions *****/
/*
 * This function is called whenever a buffer is full.
 * The content of the buffer is then converted into human-readable format and
 * sent to the PC via UART.
 *
 */
void uartTxPacket_Send(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) {
    uint_fast16_t i;
    uint_fast16_t uartTxBufferOffset=0;

    if (e & RF_EventRxEntryDone)
    {
        /* Toggle pin to indicate RX */
        PIN_setOutputValue(ledPinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));

        /* Get current unhandled data entry */
        currentDataEntry = RFQueue_getDataEntry();

        /* Handle the packet data, located at &currentDataEntry->data:
         * - Length is the first byte with the current configuration
         * - Data starts from the second byte */
        packetLength      = *(uint8_t*)(&currentDataEntry->data);
        packetDataPointer = (uint8_t*)(&currentDataEntry->data + 1);

        /* Copy the payload + the status byte to the packet variable */
        memcpy(packet, packetDataPointer, (packetLength + 1));

        RFQueue_nextEntry();

        /*
         * Start with a header message and convert each entry in the current buffer
         * to a human-readable format
         */
        uartTxBufferOffset = System_sprintf(uartTxBuffer,
            "\r\nBuffer %u finished:\r\n", PAYLOAD_LENGTH++);

        for (i = 0; i < MAX_LENGTH; i++) {
            uartTxBufferOffset += System_sprintf(uartTxBuffer + uartTxBufferOffset,
                "%u,", packet[i]);
        }
        uartTxBuffer[uartTxBufferOffset] = '\n';
        /* Send out the data via UART */
        UART_write(uart, uartTxBuffer, uartTxBufferOffset + 1);

    }
    PAYLOAD_LENGTH=0;

}

/*
 * Callback function to use the UART in callback mode. It does nothing.
 */
void uartCallback(UART_Handle handle, void *buf, size_t count) {
   return;
}

void Task_init() {

    Task_Params_init(&TaskParams);
    TaskParams.stackSize = TASK_STACK_SIZE;
    TaskParams.stack = &TaskStack;
    //TaskParams.arg0 = (UInt)1000000;

    Task_construct(&rxTask, TaskFunction, &TaskParams, NULL);
}

static void TaskFunction(UArg arg0, UArg arg1)
{
    UART_Params uartParams;
    const char echoPrompt[] = "\fRF Rx :\r\n";

    RF_Params rfParams;
    RF_Params_init(&rfParams);

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.writeMode = UART_MODE_CALLBACK;
    uartParams.writeCallback = uartCallback;
    uartParams.baudRate = 115200;
    uart = UART_open(Board_UART0, &uartParams);

    if (uart == NULL) {
        System_abort("Error opening the UART");
    }

    UART_write(uart, echoPrompt, sizeof(echoPrompt));

    if( RFQueue_defineQueue(&dataQueue,
                            rxDataEntryBuffer,
                            sizeof(rxDataEntryBuffer),
                            NUM_DATA_ENTRIES,
                            MAX_LENGTH + NUM_APPENDED_BYTES))
    {
        /* Failed to allocate space for all data entries */
        while(1);
    }

    /* Modify CMD_PROP_RX command for application needs */
    RF_cmdPropRx.pQueue = &dataQueue;           /* Set the Data Entity queue for received data */
    RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1;  /* Discard ignored packets from Rx queue */
    RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1;   /* Discard packets with CRC error from Rx queue */
    RF_cmdPropRx.maxPktLen = MAX_LENGTH;        /* Implement packet length filtering to avoid PROP_ERROR_RXBUF */
    RF_cmdPropRx.pktConf.bRepeatOk = 1;
    RF_cmdPropRx.pktConf.bRepeatNok = 1;

    /* Request access to the radio */
    rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);

    /* Set the frequency */
    RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);

    /* Enter RX mode and stay forever in RX */
    RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &uartTxPacket_Send, IRQ_RX_ENTRY_DONE);

    while(1);
}


/*
 *  ======== main ========
 */
int main(void)
{
    /* Call board init functions. */
    Board_initGeneral();
    Board_initUART();

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, pinTable);
    if(!ledPinHandle)
    {
        System_abort("Error initializing board LED pins\n");
    }

    /* Initialize task */
    Task_init();

    /* Start BIOS */
    BIOS_start();

    return (0);
}

did anyone know a complete example or project?

  • Hello,

    Please refer to the following post for example implementation of RF and UART functions:

    Assuming that you have checked for good RF link between the devices when UART is not included, do you see any error on status message after RX command execution when the device stops receiving packets? If the packet interval is short, please consider creating a new task for UART and calling it using semaphore instead of executing UART write in callback function. 

    Regards,

  • I have an example that you can try. Below is a short description

    1. One single project that does both Tx,Rx.

    2. Receives uart data from the terminal. Once you press enter, it will transmit the uart data.

    3. The other end receives the data and prints it on the uart.

    Once you build and run, open two terminals with local echo ON at baud rate 115200. Type something and press enter. The other terminal receives the data and prints it along with the string  “rx data: “

    RF is at 500 kbps. Please feel free to modify as required.

    4034.uartRxTx_CC1350_LAUNCHXL_TI.zip

  • thank you guys for your fantastic helps!!!

    that was really helpful.

    my problem is i am not familiar with TI_RTOS setup and i don't know how to modify it or adding functions.

    how can i solve my problem and read about RTOS and its setup?

    is there any docs or helpfull link?

  • You can find all information about TI-RTOS including links to traning videos here http://processors.wiki.ti.com/index.php/TI-RTOS

    Regards,

    Prashanth

  • Hello PrashanthS

    I tried to run that code it gives no error but its not working.
    I look at the ROV and i see the tasks mode is ready.So what would the problem be ?

    I need a project just like this for cc1310 if you have any source code for it would be great .
    I create the project that use like that I have opened a rfpacket cc310 project and replace the rfpacked.c with this codes c file.My project doesnt give any error.

    Regards,
    Emre OZDEMIR
  • Hello EMRE / PrashantS,

    I have also tried  same for  cc1310 launchpad, it does not give error but it doesn't reach to BIOS_start() when I put breakpoint there. 

    What cane be the reason?

  • Hello Omkar, 

    Can you try starting with the rfPacketRx example from the resource explorer for CC1310 (or CC1350). This should build and run fine on your set up. Once that is done, overwrite the source files that are in this thread. Please let us know how that goes. 

    Regards,

    Prashanth

  • Hello Prashanth,
    After posting my query, I checked one of the answer of TI employee from this forum which says to check 'scan for errors' in ROV. There I saw error as ' number of priorities is less ..." , so in cfg file I changed num of task priorites from default 4 to 5 and now it is working fine. I have followed the same what you have mentioned above.
    Thank you !

    Regards,

    Omkar