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.

CC1352P: use CC1352P-2 Development Kit. I want sent the data received by wireless to PC by uart

Part Number: CC1352P

I used a receiver, combined the two sample project uart2callback_CC1352P_2_LAUNCHXL_tirtos_ccs and rfPacketRx_CC1352P_2_LAUNCHXL_tirtos_ccs .

I want to send the received data to the PC through uart port for display. I use another wireless generator to send the data with rfListenBeforeTalk_CC1352P_2_LAUNCHXL_tirtos_ccs,

the receiver can receive the data in debuge state, but uart does not send the data to PC,  the debug must be stopped once, and the data is sent .Once when it is running, and then the receiver cannot receive the data. .

How can I solve this problem? 

It is the source I wrote.

/***** Function definitions *****/

void *mainThread(void *arg0)
{
    RF_Params rfParams;
    RF_Params_init(&rfParams);
    const char        echoPrompt[] = "Echoing characters:\r\n";
//
    UART2_Params      uartParams;
    int32_t           semStatus;
    uint32_t          status = UART2_STATUS_SUCCESS;
    uint8_t            bknumUart;
    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, pinTable);
    if (ledPinHandle == NULL)
    {
        while(1);
    }

    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 */
    /* Set the Data Entity queue for received data */
    RF_cmdPropRx.pQueue = &dataQueue;
    /* Discard ignored packets from Rx queue */
    RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1;
    /* Discard packets with CRC error from Rx queue */
    RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1;
    /* Implement packet length filtering to avoid PROP_ERROR_RXBUF */
    RF_cmdPropRx.maxPktLen = MAX_LENGTH;
    RF_cmdPropRx.pktConf.bRepeatOk = 1;
    RF_cmdPropRx.pktConf.bRepeatNok = 1;

    /* Request access to the radio */
#if defined(DeviceFamily_CC26X0R2)
    rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioSetup, &rfParams);
#else
    rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
#endif// DeviceFamily_CC26X0R2

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

    /* Enter RX mode and stay forever in RX */
    RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx,
                                               RF_PriorityNormal, &callback,
                                               RF_EventRxEntryDone);

    switch(terminationReason)
    {
        case RF_EventLastCmdDone:
            // A stand-alone radio operation command or the last radio
            // operation command in a chain finished.
            break;
        case RF_EventCmdCancelled:
            // Command cancelled before it was started; it can be caused
            // by RF_cancelCmd() or RF_flushCmd().
            break;
        case RF_EventCmdAborted:
            // Abrupt command termination caused by RF_cancelCmd() or
            // RF_flushCmd().
            break;
        case RF_EventCmdStopped:
            // Graceful command termination caused by RF_cancelCmd() or
            // RF_flushCmd().
            break;
        default:
            // Uncaught error event
            while(1);
    }

    uint32_t cmdStatus = ((volatile RF_Op*)&RF_cmdPropRx)->status;
    switch(cmdStatus)
    {
        case PROP_DONE_OK:
            // Packet received with CRC OK
            break;
        case PROP_DONE_RXERR:
            // Packet received with CRC error
            break;
        case PROP_DONE_RXTIMEOUT:
            // Observed end trigger while in sync search
            break;
        case PROP_DONE_BREAK:
            // Observed end trigger while receiving packet when the command is
            // configured with endType set to 1
            break;
        case PROP_DONE_ENDED:
            // Received packet after having observed the end trigger; if the
            // command is configured with endType set to 0, the end trigger
            // will not terminate an ongoing reception
            break;
        case PROP_DONE_STOPPED:
            // received CMD_STOP after command started and, if sync found,
            // packet is received
            break;
        case PROP_DONE_ABORT:
            // Received CMD_ABORT after command started
            break;
        case PROP_ERROR_RXBUF:
            // No RX buffer large enough for the received data available at
            // the start of a packet
            break;
        case PROP_ERROR_RXFULL:
            // Out of RX buffer space during reception in a partial read
            break;
        case PROP_ERROR_PAR:
            // Observed illegal parameter
            break;
        case PROP_ERROR_NO_SETUP:
            // Command sent without setting up the radio in a supported
            // mode using CMD_PROP_RADIO_SETUP or CMD_RADIO_SETUP
            break;
        case PROP_ERROR_NO_FS:
            // Command sent without the synthesizer being programmed
            break;
        case PROP_ERROR_RXOVF:
            // RX overflow observed during operation
            break;
        default:
            // Uncaught error event - these could come from the
            // pool of states defined in rf_mailbox.h
            while(1);
    }
    /* Create semaphore */
        semStatus = sem_init(&sem, 0, 0);

        if (semStatus != 0) {
            /* Error creating semaphore */
            while (1);
        }

        /* Create a UART in CALLBACK read mode */
        UART2_Params_init(&uartParams);
        uartParams.readMode = UART2_Mode_CALLBACK;
        uartParams.readCallback = callbackFxn;
        uartParams.baudRate = 2000000;

        uart = UART2_open(CONFIG_UART2_0, &uartParams);

        if (uart == NULL) {
            /* UART2_open() failed */
            while (1);
        }

        /* Pass NULL for bytesWritten since it's not used in this example */
        UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);

        numBytesRead = 0;

         /* Pass NULL for bytesRead since it's not used in this example */
       //  status = UART2_readTimeout(uart, &input,1, NULL,1);

         if (status != UART2_STATUS_SUCCESS) {
             /* UART2_read() failed */
             while (1);
         }
    while(1){
        /* Do not write until read callback executes */
   //      sem_wait(&sem);

         if (numUart > 0) {
             bknumUart   = numUart;
             numUart     = 0;
  //           status = UART2_write(uart, input, 100, NULL);
             UART_polling(bknumUart);
             bknumUart = 0;
             if (status != UART2_STATUS_SUCCESS) {
                 /* UART2_write() failed */
                 while (1);
             }
         }
         while(rfnum > 0){
             UART2_write(uart, &rfrxpacket[rfrp], 1, NULL);
             rfnum--;

             rfrp++;
             if(rfrp >= MAX_BUFF_LENGTH){
                 rfrp   = 0;
             }
         }


    }
}

void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
{
    int i;
    if (e & RF_EventRxEntryDone)
    {
        /* Toggle pin to indicate RX */
        PIN_setOutputValue(ledPinHandle, CONFIG_PIN_RLED,
                           !PIN_getOutputValue(CONFIG_PIN_RLED));

        /* 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 */
        for(i= 0;i< packetLength + 1 ; i++){
            rfrxpacket[rfwp] = *(packetDataPointer + i);
            rfwp++;
            rfnum++;
            if(rfwp >= MAX_BUFF_LENGTH){
                rfwp    = 0;
            }
        }

        RFQueue_nextEntry();

    }
}

  • Hi Xiaohong,

    It looks like you have some small mistakes, e.g. below where you have commented out a status, but you have not commented out the associated while loop.

             /* Pass NULL for bytesRead since it's not used in this example */
           //  status = UART2_readTimeout(uart, &input,1, NULL,1);
    
             if (status != UART2_STATUS_SUCCESS) {
                 /* UART2_read() failed */
                 while (1);
             }

    I think a good debugging step would be to run the program, press pause and see where the program counter is (see what code is being executed). You can alo use breakpoints to see which code is executed when.

    Can you explain your code architecture a bit more? What is happening in which task/thread, who is sending and pending on a semaphore etc?

  • Thank you to answer the question.

    I searched the stop point. This  

    /* Wait for semaphore */
    SemaphoreP_pend(&h->state.semSync, 100);

    Can I change it simply?  Is this means  wait 100s ?

    =>?

    SemaphoreP_pend(&h->state.semSync, 1);

     

    If there is no wireless data received, what data do I want to send to the PC at first, what should I do?

    The current situation is that I have been waiting in this place。

    /* Wait for semaphore */

    SemaphoreP_pend(&h->state.semSync, 100);

  • Hi Xiaohong,

    You can read the documentation for Semaphore_pend() here: https://dev.ti.com/tirex/explore/content/simplelink_cc13x2_26x2_sdk_5_10_00_48/docs/tirtos/sysbios/docs/cdoc/index.html 

    As you can see, this API will wait until a semaphore has been posted or the timeout has expired. Timeout is defined in system ticks. 

  • I don”t know how to use the semahore.

    I modified the source. It can send the data  once I stop the debug.

    I saw the data in PC  only twice like this.

    "Echoing characters:\r\n" is sent at first 

    paket is data 0~1D

    Cannot receive data continuously and automatically

    Base is rfPacketRx_CC1352P_2_LAUNCHXL_tirtos_ccs. I added the uart .

    I sent RF data by rfPacketTx_CC1352P_2_LAUNCHXL_tirtos_ccs once 1 second. 

    rfPacketRx.c

    /***** Includes *****/
    /* Standard C Libraries */
    #include <stdlib.h>
    
    /* TI Drivers */
    #include <ti/drivers/rf/RF.h>
    #include <ti/drivers/PIN.h>
    
    /* Driverlib Header files */
    #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)
    
    /* Board Header files */
    #include "ti_drivers_config.h"
    
    /* Application Header files */
    #include "RFQueue.h"
    #include <ti_radio_config.h>
    #include <semaphore.h>
    
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART2.h>
    #include <application.h>
    
    
    /***** Defines *****/
    
    /* 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 callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
    
    /***** Variable declarations *****/
    static RF_Object rfObject;
    static RF_Handle rfHandle;
    
    /* Pin driver handle */
    static PIN_Handle ledPinHandle;
    static PIN_State ledPinState;
    
    /* 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 */
    static uint8_t rfLength;
    
    static sem_t semrf;
    
    
    extern UART2_Handle uart;
    extern void callbackFxn(UART2_Handle handle, void *buffer, size_t count,
    void *userArg, int_fast16_t status);
    /*
    * Application LED pin configuration table:
    * - All LEDs board LEDs are off.
    */
    PIN_Config pinTable[] =
    {
    CONFIG_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
    };
    
    /***** Function definitions *****/
    
    void *rfThread(void *arg0)
    {
    
    RF_Params rfParams;
    RF_Params_init(&rfParams);
    UART2_Params uartParams;
    int32_t semStatus;
    uint32_t status = UART2_STATUS_SUCCESS;
    const char echoPrompt[] = "Echoing characters:\r\n";
    
    /* Create semaphore */
    semStatus = sem_init(&semrf, 0, 0);
    
    /* Open LED pins */
    /* ledPinHandle = PIN_open(&ledPinState, pinTable);
    if (ledPinHandle == NULL)
    {
    while(1);
    }
    */
    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 */
    /* Set the Data Entity queue for received data */
    RF_cmdPropRx.pQueue = &dataQueue;
    /* Discard ignored packets from Rx queue */
    RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1;
    /* Discard packets with CRC error from Rx queue */
    RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1;
    /* Implement packet length filtering to avoid PROP_ERROR_RXBUF */
    RF_cmdPropRx.maxPktLen = MAX_LENGTH;
    RF_cmdPropRx.pktConf.bRepeatOk = 1;
    RF_cmdPropRx.pktConf.bRepeatNok = 1;
    
    /* Request access to the radio */
    #if defined(DeviceFamily_CC26X0R2)
    rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioSetup, &rfParams);
    #else
    rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
    #endif// DeviceFamily_CC26X0R2
    
    /* Set the frequency */
    RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
    
    /* Enter RX mode and stay forever in RX */
    RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx,
    RF_PriorityNormal, &callback,
    RF_EventRxEntryDone);
    
    switch(terminationReason)
    {
    case RF_EventLastCmdDone:
    // A stand-alone radio operation command or the last radio
    // operation command in a chain finished.
    break;
    case RF_EventCmdCancelled:
    // Command cancelled before it was started; it can be caused
    // by RF_cancelCmd() or RF_flushCmd().
    break;
    case RF_EventCmdAborted:
    // Abrupt command termination caused by RF_cancelCmd() or
    // RF_flushCmd().
    break;
    case RF_EventCmdStopped:
    // Graceful command termination caused by RF_cancelCmd() or
    // RF_flushCmd().
    break;
    default:
    // Uncaught error event
    while(1);
    }
    
    uint32_t cmdStatus = ((volatile RF_Op*)&RF_cmdPropRx)->status;
    switch(cmdStatus)
    {
    case PROP_DONE_OK:
    // Packet received with CRC OK
    break;
    case PROP_DONE_RXERR:
    // Packet received with CRC error
    break;
    case PROP_DONE_RXTIMEOUT:
    // Observed end trigger while in sync search
    break;
    case PROP_DONE_BREAK:
    // Observed end trigger while receiving packet when the command is
    // configured with endType set to 1
    break;
    case PROP_DONE_ENDED:
    // Received packet after having observed the end trigger; if the
    // command is configured with endType set to 0, the end trigger
    // will not terminate an ongoing reception
    break;
    case PROP_DONE_STOPPED:
    // received CMD_STOP after command started and, if sync found,
    // packet is received
    break;
    case PROP_DONE_ABORT:
    // Received CMD_ABORT after command started
    break;
    case PROP_ERROR_RXBUF:
    // No RX buffer large enough for the received data available at
    // the start of a packet
    break;
    case PROP_ERROR_RXFULL:
    // Out of RX buffer space during reception in a partial read
    break;
    case PROP_ERROR_PAR:
    // Observed illegal parameter
    break;
    case PROP_ERROR_NO_SETUP:
    // Command sent without setting up the radio in a supported
    // mode using CMD_PROP_RADIO_SETUP or CMD_RADIO_SETUP
    break;
    case PROP_ERROR_NO_FS:
    // Command sent without the synthesizer being programmed
    break;
    case PROP_ERROR_RXOVF:
    // RX overflow observed during operation
    break;
    default:
    // Uncaught error event - these could come from the
    // pool of states defined in rf_mailbox.h
    while(1);
    }
    /* Create a UART in CALLBACK read mode */
    UART2_Params_init(&uartParams);
    uartParams.readMode = UART2_Mode_CALLBACK;
    uartParams.readCallback = callbackFxn;
    uartParams.baudRate = 2000000;
    
    uart = UART2_open(CONFIG_UART2_0, &uartParams);
    
    if (uart == NULL) {
    /* UART2_open() failed */
    while (1);
    }
    
    /* Pass NULL for bytesWritten since it's not used in this example */
    UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);
    while(1){
    sem_wait(&semrf);
    // sem_post(&sem);
    
    UART2_write(uart, &packet, packetLength, NULL);
    }
    }
    
    void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
    {
    if (e & RF_EventRxEntryDone)
    {
    /* Toggle pin to indicate RX */
    PIN_setOutputValue(ledPinHandle, CONFIG_PIN_RLED,
    !PIN_getOutputValue(CONFIG_PIN_RLED));
    
    /* 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));
    rfLength = packetLength + 1;
    
    sem_post(&semrf);
    
    RFQueue_nextEntry();
    }
    }
    
    
    
    
    
    
    
    
    
    

    main_tirtos.c

    /*
     * application.h
     *
     *  Created on: 2021/06/15
     *      Author: ZOU
     */
    
    #ifndef APPLICATION_H_
    #define APPLICATION_H_
    
    /* 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) */
    
    
    static uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */
    static uint8_t  rfLength;
    
    static sem_t sem;
    
    
    #endif /* APPLICATION_H_ */
    

    extern void *rfThread(void *arg0);
    extern void *uartThread(void *arg0);
    
    /* Stack size in bytes */
    #define THREADSTACKSIZE    2096
    
    /*
     *  ======== main ========
     */
    int main(void)
    {
        pthread_t           thread;
        pthread_attr_t      attrs;
        struct sched_param  priParam;
        int                 retc;
        int                 detachState;
    
        /* Call driver init functions */
        Board_initGeneral();
    
        /* Set priority and stack size attributes */
        pthread_attr_init(&attrs);
        priParam.sched_priority = 1;
    
        detachState = PTHREAD_CREATE_DETACHED;
        retc = pthread_attr_setdetachstate(&attrs, detachState);
        if (retc != 0) {
            /* pthread_attr_setdetachstate() failed */
            while (1);
        }
    
        pthread_attr_setschedparam(&attrs, &priParam);
    
        retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
        if (retc != 0) {
            /* pthread_attr_setstacksize() failed */
            while (1);
        }
    
        retc = pthread_create(&thread, &attrs, rfThread, NULL);
        if (retc != 0) {
            /* pthread_create() failed */
            while (1);
        }
    
    //    priParam.sched_priority = 2;
    //    pthread_attr_setschedparam(&attrs, &priParam);
    //    retc = pthread_create(&thread, &attrs, uartThread, NULL);
    //    if (retc != 0) {
            /* pthread_create() failed */
    //        while (1);
    //    }
    

  • Hi Xiahong,

    When you say you start and stop the debug, do you mean that you start and stop a debug session? Did you remember to press play after starting the debug session?

  • When breakpoint is set in lines 250 and 278 of rfPacketRx.c, uart can send data. When it is not set, no data is sent.

  • Hi Xiaohong,

    My tip for debugging this kind of issue is to ty to take a step back, get an overview of the code you are running. Since the data is not sent unless you set a breakpoint, it sounds like something could be blocking it?

  • It seems that cannot enter the main while loop after the wireless receiving interrupt。

  • Hi Xiahong,

    Ok, how is the RF RX structured? Is it spinning somewhere, keeping the PC from going back to main loop?