Tool/software:
I am using Rf Uart Brige No rtos proprietary mode Example code
I need to some delay between receiving packet and transmit packet
what rf driver api should be used
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.
Tool/software:
I am using Rf Uart Brige No rtos proprietary mode Example code
I need to some delay between receiving packet and transmit packet
what rf driver api should be used
i trying to do send RF data packect after some delay
question 1: I am able to to receive the rf data packect in my UART port, after that I need to transmit the my payload data packet from UART to SmartRF .For sending these data packect I need to some dealy.
question 2: What I need is first I need to transmit some data payload from UART to Smart RF(RF DATA PACKET) , again the same data payload should transmit from Smart RF to Rf uart data.
/* Standard C Libraries */ #include <stdlib.h> #include <stdint.h> #include <stddef.h> #include <stdio.h> /* TI Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/GPIO.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> /* ======== uart2 ======== */ #include <ti/drivers/UART2.h> /***** Defines *****/ /* Packet RX Configuration */ #define DATA_ENTRY_HEADER_SIZE 8 /* Constant header size of a Generic Data Entry */ #define MAX_LENGTH 64 /* 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) */ #define NO_PACKET 0 #define PACKET_RECEIVED 1 /*******Global variable declarations*********/ static RF_Object rfObject; static RF_Handle rfHandle; static RF_CmdHandle rfPostHandle; UART2_Handle uart; UART2_Params uartParams; static char input[MAX_LENGTH]; #define PAYLOAD_LENGTH 20 static uint8_t packet_1[PAYLOAD_LENGTH]; uint8_t keyboard_data=10; uint8_t Tx_1=2; uint8_t Rx_1=2; uint8_t mode=1; uint8_t time=200; uint8_t tx_time=200; uint8_t rx_time=10; int32_t UARTwrite_semStatus; int_fast16_t status = UART2_STATUS_SUCCESS; volatile uint8_t packetRxCb; volatile size_t bytesReadCount; /* 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 */ /***** Function definitions *****/ static void ReceivedOnRFcallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); static void ReceiveonUARTcallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status); void *mainThread(void *arg0) { packetRxCb = NO_PACKET; // to print in the console printf("hello \n"); RF_Params rfParams; RF_Params_init(&rfParams); 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); } GPIO_setConfig(CONFIG_GPIO_RLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_write(CONFIG_GPIO_RLED, CONFIG_GPIO_LED_OFF); GPIO_setConfig(CONFIG_GPIO_GLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_write(CONFIG_GPIO_GLED, CONFIG_GPIO_LED_OFF); /*Modifies settings to be able to do RX*/ /* 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; RF_cmdPropTx.pPkt = packet; RF_cmdPropTx.startTrigger.triggerType = TRIG_NOW; /* Set the max amount of bytes to read via UART */ size_t bytesToRead = MAX_LENGTH; bytesReadCount = 0; /* Initialize UART with callback read mode */ UART2_Params_init(&uartParams); uartParams.baudRate = 115200; uartParams.readMode = UART2_Mode_CALLBACK; uartParams.readCallback = ReceiveonUARTcallback; uartParams.readReturnMode = UART2_ReadReturnMode_PARTIAL; /* Access UART */ uart = UART2_open(CONFIG_UART2_0, &uartParams); /* Print to the terminal that the program has started */ const char startMsg[] = "\r\nRF-UART bridge started:\r\n"; const char ok[] = "\r\n Transmit data \r\n"; const char ok_1[] = "\r\n Received data \r\n"; UART2_write(uart, startMsg, sizeof(startMsg), NULL); /* 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); rfPostHandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &ReceivedOnRFcallback, RF_EventRxEntryDone); UART2_read(uart, &input, bytesToRead, NULL); while(1) { /* Check if anything has been received via RF*/ if(packetRxCb) { memcpy(input, packet, (packetLength)); size_t bytesWritten = 0; while (bytesWritten == 0) { status = UART2_write(uart, &input, packetLength, &bytesWritten); if (status != UART2_STATUS_SUCCESS) { /* UART2_write() failed */ while (1); } } /* Reset RF RX callback flag */ packetRxCb = NO_PACKET; UART2_write(uart, ok, sizeof(ok), NULL); } /* Check if anything has been * received via UART*/ if (bytesReadCount != 0) { /*The packet length is set to the number of * bytes read by UART2_read() */ //RF_cmdPropTx.pktLen = bytesReadCount; // I need to transmit 10 data // Here I want to put delay so that wheneve I click the Receive button from Samrt RF at that time only below data should send RF_cmdPropTx.pktLen = 10; int i; for (i=0; i<20; i++) { //uint8_t* buffer8 = (uint8_t*) input; //packet[i] = buffer8[i]; packet[2] = Tx_1; packet[3] = Rx_1 ; packet[4] = mode ; packet[5] = time ; packet[6] = tx_time ; packet[7] = rx_time ; // packet[i]=input[i]; UART2_write(uart, ok_1, sizeof(ok), NULL); GPIO_toggle(CONFIG_GPIO_GLED); } /*Cancel the ongoing command*/ RF_cancelCmd(rfHandle, rfPostHandle, 1); /*Send packet*/ //RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 0); RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL , 0); /*The packet length is set to the number of * bytes read by UART2_read() */ /* Toggle green led to indicate TX */ // GPIO_toggle(CONFIG_GPIO_GLED); /* Resume RF RX */ // rfPostHandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &ReceivedOnRFcallback, RF_EventRxEntryDone); bytesReadCount = 0; /* Resume UART read */ UART2_read(uart, &input, bytesToRead, NULL); } } } /* Callback function called when data is received via RF * Function copies the data in a variable, packet, and sets packetRxCb */ void ReceivedOnRFcallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if (e & RF_EventRxEntryDone) { GPIO_toggle(CONFIG_GPIO_RLED); /* Get current unhandled data entry */ currentDataEntry = RFQueue_getDataEntry(); //loads data from entry /* Handle the packet data, located at ¤tDataEntry->data: * - Length is the first byte with the current configuration * - Data starts from the second byte */ packetLength = *(uint8_t*)(¤tDataEntry->data); //gets the packet length (send over with packet) packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1); //data starts from 2nd byte /* Copy the payload + the status byte to the packet variable */ memcpy(packet, packetDataPointer, (packetLength + 1)); /* Move read entry pointer to next entry */ RFQueue_nextEntry(); packetRxCb = PACKET_RECEIVED; } } /* Callback function called when data is received via UART */ void ReceiveonUARTcallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status) { if (status != UART2_STATUS_SUCCESS) { /* RX error occured in UART2_read() */ while (1) { } } bytesReadCount = count; }
question 1: I am able to to receive the rf data packect in my UART port, after that I need to transmit the my payload data packet from UART to SmartRF .For sending these data packect I need to some dealy.
Can you try something like:
question 2: What I need is first I need to transmit some data payload from UART to Smart RF(RF DATA PACKET) , again the same data payload should transmit from Smart RF to Rf uart data.
If you are transmitting from SmartRF to the rfUart example, then you could do something like:
Basically you just need to make sure the RX is turned on before any TX.
I need to explore somthing different Using Rf Uart Brige example No rtos proprietary mode
what I understant from this example is First rf data packet is received and received data is displayed in UART.
but what I need to do is insted of receiving rf data packet , I need to transmit the rf data packet and that particular data should be display in UART
Thanks for sharing more details of your use case.
I will look into and provide an update within 3 business days.
I need to transmit the rf data packet and that particular data should be display in UART
In that case, the application already knows what data it wants to transmit. So before transmitting it, print it out over uart.