我使用了一个接收器,将两个示例项目 uart2callback_CC1352P_2_LAUNCHXL_tirtos_ccs 和 rfPacketRx_CC1352P_2_LAUNCHXL_tirtos_ccs 组合在一起。
我想通过 UART 端口将接收到的数据发送到 PC 进行显示。 我使用另一个无线发生器通过 rfListenBeforeTalk CC1352P_2_LAUNCHXL_tirtos_ccs 发送数据、
接收器可以在 debugge 状态下接收数据、但 UART 不会将数据发送到 PC、 调试必须停止一次、数据被发送。当数据正在运行时、接收器无法接收数据。 。
如何解决此问题?
它是我编写的源代码。
/***** 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 ¤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 */
for(i= 0;i< packetLength + 1 ; i++){
rfrxpacket[rfwp] = *(packetDataPointer + i);
rfwp++;
rfnum++;
if(rfwp >= MAX_BUFF_LENGTH){
rfwp = 0;
}
}
RFQueue_nextEntry();
}
}
