Other Parts Discussed in Thread: CC2650, SYSBIOS
Hello,
I started with the rfEasyLink example just to get familiar with TI-Rtos programming, ten i will switch to the BLE protocol.
I'm using the rfEasyLink example from ti resource explorer, so I loaded rfEasyLinkRx on the first CC2650 and rfEasyLinkTx on the other CC2650.
Now, I am trying to send the data received from the CC2650 receiver over UART to my computer
I create two Tasks, one for uart driver and the other for RF driver. Here my codes for transmitter CC2650 and Receiver CC2650.
I tested the uart driver and it worked well. but when I try printing out the received data from TX CC2650 I got only zeros!
Could you please help me to figure out why I did not get the right data?
Best regards
**************************** TX *******************************
/*
* ======== rfEasyLinkTx.c ========
*/
/* XDCtools Header files */
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Clock.h>
/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
/* Board Header files */
#include "Board.h"
/* EasyLink API Header files */
#include "easylink/EasyLink.h"
/* Undefine to not use async mode */
#define RFEASYLINKTX_ASYNC
#define RFEASYLINKTX_TASK_STACK_SIZE 1024
#define RFEASYLINKTX_TASK_PRIORITY 2
#define RFEASYLINKTX_BURST_SIZE 10
#define RFEASYLINKTXPAYLOAD_LENGTH 30
Task_Struct txTask; /* not static so you can see in ROV */
static Task_Params txTaskParams;
static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];
/* Pin driver handle */
static PIN_Handle pinHandle;
static PIN_State pinState;
/*
* 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
};
static uint16_t seqNumber;
#ifdef RFEASYLINKTX_ASYNC
static Semaphore_Handle txDoneSem;
#endif //RFEASYLINKTX_ASYNC
#ifdef RFEASYLINKTX_ASYNC
void txDoneCb(EasyLink_Status status)
{
if (status == EasyLink_Status_Success)
{
/* Toggle LED1 to indicate TX */
PIN_setOutputValue(pinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
}
else if(status == EasyLink_Status_Aborted)
{
/* Toggle LED2 to indicate command aborted */
PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));
}
else
{
/* Toggle LED1 and LED2 to indicate error */
PIN_setOutputValue(pinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));
}
Semaphore_post(txDoneSem);
}
#endif //RFEASYLINKTX_ASYNC
static void rfEasyLinkTxFnx(UArg arg0, UArg arg1)
{
uint8_t txBurstSize = 0;
#ifdef RFEASYLINKTX_ASYNC
/* Create a semaphore for Async */
Semaphore_Params params;
Error_Block eb;
/* Init params */
Semaphore_Params_init(¶ms);
Error_init(&eb);
/* Create semaphore instance */
txDoneSem = Semaphore_create(0, ¶ms, &eb);
#endif //TX_ASYNC
EasyLink_init(EasyLink_Phy_Custom);
/* If you wich to use a frequency other than the default use
* the below API
* EasyLink_setFrequency(868000000);
*/
/* Set output power to 12dBm */
EasyLink_setRfPwr(12);
while(1) {
EasyLink_TxPacket txPacket = { {0}, 0, 0, {0} };
/* Create packet with incrementing sequence number and random payload */
txPacket.payload[0] = (uint8_t)(seqNumber >> 8);
txPacket.payload[1] = (uint8_t)(seqNumber++);
uint8_t i;
for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)
{
txPacket.payload[i] = 0xFF;
}
txPacket.len = RFEASYLINKTXPAYLOAD_LENGTH;
txPacket.dstAddr[0] = 0xaa;
/* Add a Tx delay for > 500ms, so that the abort kicks in and brakes the burst */
if(txBurstSize++ >= RFEASYLINKTX_BURST_SIZE)
{
/* Set Tx absolute time to current time + 1s */
txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1000);
txBurstSize = 0;
}
/* Else set the next packet in burst to Tx in 100ms */
else
{
/* Set Tx absolute time to current time + 100ms */
txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(100);
}
#ifdef RFEASYLINKTX_ASYNC
EasyLink_transmitAsync(&txPacket, txDoneCb);
/* Wait 300ms for Tx to complete */
if(Semaphore_pend(txDoneSem, (300000 / Clock_tickPeriod)) == FALSE)
{
/* TX timed out, abort */
if(EasyLink_abort() == EasyLink_Status_Success)
{
/*
* Abort will cause the txDoneCb to be called, and the txDoneSem ti
* Be released. So we must consume the txDoneSem
* */
Semaphore_pend(txDoneSem, BIOS_WAIT_FOREVER);
}
}
#else
EasyLink_Status result = EasyLink_transmit(&txPacket);
if (result == EasyLink_Status_Success)
{
/* Toggle LED1 to indicate TX */
PIN_setOutputValue(pinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
}
else
{
/* Toggle LED1 and LED2 to indicate error */
PIN_setOutputValue(pinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));
}
#endif //RFEASYLINKTX_ASYNC
}
}
void txTask_init(PIN_Handle inPinHandle) {
pinHandle = inPinHandle;
Task_Params_init(&txTaskParams);
txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;
txTaskParams.stack = &txTaskStack;
txTaskParams.arg0 = (UInt)1000000;
Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);
}
/*
* ======== main ========
*/
int main(void)
{
/* Call board init functions. */
Board_initGeneral();
/* Open LED pins */
pinHandle = PIN_open(&pinState, pinTable);
if(!pinHandle) {
System_abort("Error initializing board LED pins\n");
}
/* Clear LED pins */
PIN_setOutputValue(pinHandle, Board_LED1, 0);
PIN_setOutputValue(pinHandle, Board_LED2, 0);
txTask_init(pinHandle);
/* Start BIOS */
BIOS_start();
return (0);
}
**************************** RX *******************************
/*
* ======== rfEasyLinkRx.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Clock.h>
/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>
/* Board Header files */
#include "Board.h"
/* EasyLink API Header files */
#include "easylink/EasyLink.h"
/***** Defines *****/
#define UARTTASKSTACKSIZE 768
/* Undefine to remove address filter and async mode */
#define RFEASYLINKRX_ASYNC
#define RFEASYLINKRX_ADDR_FILTER
#define RFEASYLINKEX_TASK_STACK_SIZE 1024
#define RFEASYLINKEX_TASK_PRIORITY 2 //it was 2 before
/***** Variable declarations *****/
static Task_Params rxTaskParams;
Task_Struct rxTask; /* not static so you can see in ROV */
static uint8_t rxTaskStack[RFEASYLINKEX_TASK_STACK_SIZE];
Task_Struct uart_taskStruct;
Char uart_taskStack[UARTTASKSTACKSIZE];
/* 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
};
/* The RX Output struct contains statistics about the RX operation of the radio */
PIN_Handle pinHandle;
#ifdef RFEASYLINKRX_ASYNC
static Semaphore_Handle rxDoneSem;
#endif
/***** Function definitions *****/
#ifdef RFEASYLINKRX_ASYNC
void rxDoneCb(EasyLink_RxPacket * rxPacket, EasyLink_Status status)
{
if (status == EasyLink_Status_Success)
{
/* Toggle LED2 to indicate RX */
PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));
}
else if(status == EasyLink_Status_Aborted)
{
/* Toggle LED1 to indicate command aborted */
PIN_setOutputValue(pinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
}
else
{
/* Toggle LED1 and LED2 to indicate error */
PIN_setOutputValue(pinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));
}
Semaphore_post(rxDoneSem);
}
#endif
static void rfEasyLinkRxFnx(UArg arg0, UArg arg1)
{
const char echoPrompt[] = "Hello Badra \n";
int i;
UART_Handle uart;
Task_Params uart_taskParams;
UART_Params uartParams;
Task_Params_init(&uart_taskParams);
uart_taskParams.stackSize = UARTTASKSTACKSIZE;
uart_taskParams.stack = &uart_taskStack;
uart_taskParams.priority = 1;
/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 1500000;
uart = UART_open(Board_UART0, &uartParams);
if (uart == NULL) {
System_abort("Error opening the UART");
}
#ifndef RFEASYLINKRX_ASYNC
EasyLink_RxPacket rxPacket = {0};
#endif
#ifdef RFEASYLINKRX_ASYNC
/* Create a semaphore for Async*/
Semaphore_Params params;
Error_Block eb;
/* Init params */
Semaphore_Params_init(¶ms);
Error_init(&eb);
/* Create semaphore instance */
rxDoneSem = Semaphore_create(0, ¶ms, &eb);
#endif //RFEASYLINKRX_ASYNC
EasyLink_init(EasyLink_Phy_Custom);
/* If you wich to use a frequency other than the default use
* the below API
* EasyLink_setFrequency(868000000);
*/
#ifdef RFEASYLINKRX_ADDR_FILTER
uint8_t addrFilter = 0xaa;
EasyLink_enableRxAddrFilter(&addrFilter, 1, 1);
#endif //RFEASYLINKRX_ADDR_FILTER
while(1) {
#ifdef RFEASYLINKRX_ASYNC
EasyLink_RxPacket rxPacket = {{0}, 0, 0, 0, 0, {0}};
onst char echoPrompt[] = "Hello Badra \n";
EasyLink_receiveAsync(rxDoneCb, 0);
//for (i = 0; i>30; i++){
UART_write(uart, rxPacket.payload, sizeof(rxPacket.len));
//UART_write(uart, echoPrompt, sizeof(echoPrompt));
//}
/* Wait 300ms for Rx */
if(Semaphore_pend(rxDoneSem, (300000 / Clock_tickPeriod)) == FALSE)
{
/* RX timed out abort */
if(EasyLink_abort() == EasyLink_Status_Success)
{
/* Wait for the abort */
Semaphore_pend(rxDoneSem, BIOS_WAIT_FOREVER);
}
}
#else
rxPacket.absTime = 0;
EasyLink_Status result = EasyLink_receive(&rxPacket);
if (result == EasyLink_Status_Success)
{
/* Toggle LED2 to indicate RX */
PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));
}
else
{
/* Toggle LED1 and LED2 to indicate error */
PIN_setOutputValue(pinHandle, Board_LED1,!PIN_getOutputValue(Board_LED1));
PIN_setOutputValue(pinHandle, Board_LED2,!PIN_getOutputValue(Board_LED2));
}
#endif //RX_ASYNC
}
}
void rxTask_init(PIN_Handle ledPinHandle) {
pinHandle = ledPinHandle;
Task_Params_init(&rxTaskParams);
rxTaskParams.stackSize = RFEASYLINKEX_TASK_STACK_SIZE;
rxTaskParams.priority = RFEASYLINKEX_TASK_PRIORITY;
rxTaskParams.stack = &rxTaskStack;
rxTaskParams.arg0 = (UInt)1000000;
Task_construct(&rxTask, rfEasyLinkRxFnx, &rxTaskParams, NULL);
}
/*
* ======== main ========
*/
int main(void)
{ //Task_Params uart_taskParams;
/* 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");
}
/* Clear LED pins */
PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
PIN_setOutputValue(ledPinHandle, Board_LED2, 0);
rxTask_init(ledPinHandle);
/* Start BIOS */
BIOS_start();
return (0);
}