串口丢失字节
PC通过串口接收协调器的数据时,第一组数据是正确的,从第二组数据开始以后接收到的每次都少一个字节,而且这个字节是第二个字节。
1:把从无线接收到的数据发送到串口
case AF_INCOMING_MSG_CMD:
simpleApp_ProcessMSGCmd( MSGpkt );
2:把从上位机串口接收到的数据发送到协调器,用的回调函数rxCB()。串口设置如下:
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE; // 2x30 don't care - see uart driver.
uartConfig.baudRate = SERIAL_APP_BAUD;
uartConfig.flowControl = FALSE;
uartConfig.flowControlThreshold = SERIAL_APP_THRESH; // 2x30 don't care - see uart driver.
uartConfig.rx.maxBufSize = SERIAL_APP_RX_SZ; // 2x30 don't care - see uart driver.
uartConfig.tx.maxBufSize = SERIAL_APP_TX_SZ; // 2x30 don't care - see uart driver.
uartConfig.idleTimeout = SERIAL_APP_IDLE; // 2x30 don't care - see uart driver.
uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver.
uartConfig.callBackFunc = rxCB; //MT_UartProcessZToolData
HalUARTOpen (0, &uartConfig);
回调函数如下:
static void rxCB(uint8 port, uint8 event)
{
uint8 *buf, len;
if (!(buf = osal_mem_alloc(SERIAL_RX_CNT))) return;
/* HAL UART Manager will turn flow control back on if it can after read.
* Reserve 1 byte for the 'sequence number'.*/
len = HalUARTRead(0,buf,SERIAL_RX_CNT);
HalUARTWrite(0,buf,len);
if(!len)
{ // Length is not expected to ever be zero.
osal_mem_free( buf );
return;
}
otaBuf = buf;
otalen = len;
osal_set_event(LocDongle_TaskID, SERIAL_PORT_MSG_DATA_EVT);
}