Part Number:CC1352P
请教一下,如何使用两台CC1352P-2 Development Kit开发板,利用样本程序,想实现两台机器的连续无线通讯。
使用甲PC机输入一串字符到单片机,另一台单片机接受字符串后在乙PC机上显示。
单独无线通讯,和单独PC到芯片的通讯通过DEBUG已经试通,但PC到无线通讯再PC接收一直没有试通,想请教一下大家。
我PC到单片机通讯利用的是 uart2callback_CC1352P_2_LAUNCHXL_tirtos_ccs
单片机到单片机无线通讯利用的是 rfPacketRx_CC1352P_2_LAUNCHXL_tirtos_ccs
下面是我修改过的rfPacketRx_CC1352P_2_LAUNCHXL_tirtos_ccs
无线送信端我是用了rfListenBeforeTalk_CC1352P_2_LAUNCHXL_tirtos_ccs,改造成每秒发射一组30byte的固定数字。
现在问题是,在下面source 289行,终端中加中断点时,开启无线送信,接入DEBUG,
可以看到无线收信发生,收到数据也对,
然后继续运行在265行,将数据送到PC上。
但是,不加中断点时,直接运行,PC上看不到接收到的数据。
直接运行,运行中在289行加上中断点,程序也可以停下,然后运行到265行将数据送到PC上。
但这个操作几次之后,无线信号再也不能接受数据了,可能发生了溢出错误,这个也不知如何处理。
感觉运程设计可能有些问题,请指点一下。
/***** 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_LENGTH30 /* Max length byte the radio will accept */
//#define NUM_DATA_ENTRIES2 /* NOTE: Only two data entries supported at the moment */
//#define NUM_APPENDED_BYTES2 /* 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_Handleuart;
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_ParamsuartParams;int32_tsemStatus;uint32_tstatus = UART2_STATUS_SUCCESS;inti;/* Create semaphore */semStatus = sem_init(&semrf, 0, 0);/* Open LED pins */
/*ledPinHandle = PIN_open(&ledPinState, pinTable);if (ledPinHandle == NULL){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);for(i= 0;i<500;i++);UART2_close(uart);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);
#elserfHandle = 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 eventwhile(1);}uint32_t cmdStatus = ((volatile RF_Op*)&RF_cmdPropRx)->status;switch(cmdStatus){case PROP_DONE_OK:// Packet received with CRC OKbreak;case PROP_DONE_RXERR:// Packet received with CRC errorbreak;case PROP_DONE_RXTIMEOUT:// Observed end trigger while in sync searchbreak;case PROP_DONE_BREAK:// Observed end trigger while receiving packet when the command is// configured with endType set to 1break;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 receptionbreak;case PROP_DONE_STOPPED:// received CMD_STOP after command started and, if sync found,// packet is receivedbreak;case PROP_DONE_ABORT:// Received CMD_ABORT after command startedbreak;case PROP_ERROR_RXBUF:// No RX buffer large enough for the received data available at// the start of a packetbreak;case PROP_ERROR_RXFULL:// Out of RX buffer space during reception in a partial readbreak;case PROP_ERROR_PAR:// Observed illegal parameterbreak;case PROP_ERROR_NO_SETUP:// Command sent without setting up the radio in a supported// mode using CMD_PROP_RADIO_SETUP or CMD_RADIO_SETUPbreak;case PROP_ERROR_NO_FS:// Command sent without the synthesizer being programmedbreak;case PROP_ERROR_RXOVF:// RX overflow observed during operationbreak;default:// Uncaught error event - these could come from the// pool of states defined in rf_mailbox.hwhile(1);}while(1){sem_wait(&semrf);
//sem_post(&sem);if(packetLength > 0) {uart = UART2_open(CONFIG_UART2_0, &uartParams);if (uart == NULL) {/* UART2_open() failed */while (1);}status = UART2_write(uart, packet, rfLength, NULL);for(i= 0;i<500;i++);UART2_close(uart);}}
}
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 ¤tDataEntry->data:* - Length is the first byte with the current configuration* - Data starts from the second byte */packetLength= *(uint8_t*)(¤tDataEntry->data);packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1);/* Copy the payload + the status byte to the packet variable */memcpy(packet, packetDataPointer, (packetLength + 1));rfLength= packetLength + 1;
//RF_close(&rfObject);sem_post(&semrf);RFQueue_nextEntry();}
}
Kevin Qiu1:
使用例程rfPacketTx搭配rfPacketRx会简单一些,最后再将串口的程序添加进去
,
XIAOHONG ZOU:
无线搭配哪种都没问题,我的问题是串口添加进去后,无线收信的数据不能通过串口输出到PC,不知道为什么。同样 PC的数据传进单片机后,也不能发射无线信号。是串口和无线两个功能合并的问题。
其实我的问题是rfPacketTx或者rfPacketRx 怎么加入uart的问题。另外还有我想同一块板能进行rfPacketT和rfPacketRx 的切换,请问如何做?是否有例子?
,
Kevin Qiu1:
添加uart到rfPacketTx和rfPacketRx参考这里的回复 https://e2echina.ti.com/support/wireless-connectivity/sub-1-ghz/f/sub-1-ghz-forum/204857/cc1310-rf_packetrx
Tx和Rx切换参考这里的实现方式:https://www.ti2k.com/wp-content/uploads/ti2k/DeyiSupport_otherwireless_cc1310-tx-rx-uart
TI中文支持网


