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.

这句代码时好时坏:SampleApp_TxLen += HalUARTRead(0, SampleApp_TxBuf+SampleApp_TxLen, 1);



现在是中国农历春节,大年初一给你们发了个新贴,如果能够得到你们的有效回复,那将相当于给了我一个大大的春节祝福,在此先谢过了。切入正题:我向串口0,向ESP8266 发送了 AT+RST指令---HalUARTWrite(0, "AT+RST\r", 8); 想通过 HalUARTRead(0, SampleApp_TxBuf+SampleApp_TxLen, 1); 读到OK的返回值。结果是有时可以有时不可以。请问问题在哪里?我的代码如下:裁剪过多余的部分

协议栈版本:ZStack-CC2530-2.3.0-1.4.0

void SampleApp_Init( uint8 task_id )
{
unsigned char tmp[10];
halUARTCfg_t uartConfig;

SampleApp_TaskID = task_id;
SampleApp_RxSeq = 0xC3;
SampleApp_NwkState = DEV_INIT;

    MT_UartInit(); //串口初始化
    MT_UartRegisterTaskID(task_id); //注册串口任务
    HalUARTWrite(0, "+++", 3); //WiFi模块不要透传模式
    osal_memset(tmp,0,10);
    tmp[0] = HAL_UART_DMA+0x30;//1
    tmp[1] = HAL_UART_ISR+0x30;//2
    tmp[2] = HAL_UART_USB+0x30;//0
    HalUARTWrite(1, tmp, 6);
}

void SampleApp_CallBack(uint8 port, uint8 event)
{
(void)port;

SampleApp_TxLen += HalUARTRead(SAMPLE_APP_PORT, SampleApp_TxBuf+SampleApp_TxLen, 1);

if(atflag==0&&SampleApp_TxLen>0) //SampleApp_TxLen没法大于0
{
if(strstr((const char*)SampleApp_TxBuf,"OK"))
{
HalUARTWrite(1,SampleApp_TxBuf, SampleApp_TxLen);HalUARTWrite(1,"\r\n", 2);
atflag = 1;
SampleApp_TxLen=0;
osal_memset(SampleApp_TxBuf, 0, SAMPLE_APP_TX_MAX);
return ;
}
else
{

}
}
}

UINT16 SampleApp_ProcessEvent( uint8 task_id, UINT16 events )
{

HalUARTWrite(0, "AT+RST\r", 8);

osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT,1000 );
}


extern void SampleApp_CallBack(uint8 port, uint8 event);
void MT_UartInit ()
{
halUARTCfg_t uartConfig;

/* Initialize APP ID */
App_TaskID = 0;

/* UART Configuration */
uartConfig.configured = TRUE;
uartConfig.baudRate = MT_UART_DEFAULT_BAUDRATE;
uartConfig.flowControl = 1;//MT_UART_DEFAULT_OVERFLOW;
uartConfig.flowControlThreshold = MT_UART_DEFAULT_THRESHOLD;
uartConfig.rx.maxBufSize = MT_UART_DEFAULT_MAX_RX_BUFF;
uartConfig.tx.maxBufSize = MT_UART_DEFAULT_MAX_TX_BUFF;
uartConfig.idleTimeout = MT_UART_DEFAULT_IDLE_TIMEOUT;
uartConfig.intEnable = TRUE;
#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
uartConfig.callBackFunc = SampleApp_CallBack;
#elif defined (ZAPP_P1) || defined (ZAPP_P2)
uartConfig.callBackFunc = SampleApp_CallBack;
#else
uartConfig.callBackFunc = NULL;
#endif

/* Start UART */
#if defined (MT_UART_DEFAULT_PORT)
HalUARTOpen (MT_UART_DEFAULT_PORT, &uartConfig);
HalUARTOpen (1, &uartConfig);
#else
/* Silence IAR compiler warning */
(void)uartConfig;
#endif

/* Initialize for ZApp */
#if defined (ZAPP_P1) || defined (ZAPP_P2)
/* Default max bytes that ZAPP can take */
MT_UartMaxZAppBufLen = 1;
MT_UartZAppRxStatus = MT_UART_ZAPP_RX_READY;
#endif

}