以下是设置void USER_Uart_IO_Init(void)
{
uint16_t timer;
uint32_t pclk;
stc_uart_config_t stcConfig;
stc_uart_irq_cb_t stcUartIrqCb;
stc_uart_multimode_t stcMulti;
stc_uart_baud_config_t stcBaud;
stc_bt_config_t stcBtConfig;
// en_uart_mmdorck_t enTb8;
DDL_ZERO_STRUCT(stcUartIrqCb);
DDL_ZERO_STRUCT(stcMulti);
DDL_ZERO_STRUCT(stcBaud);
DDL_ZERO_STRUCT(stcBtConfig);
Gpio_InitIOExt(1,4,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_InitIOExt(1,5,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
//ͨµÀ¶Ë¿ÚÅäÖÃ
Gpio_SetFunc_UART0TX_P14();
Gpio_SetFunc_UART0RX_P15();
//ÍâÉèʱÖÓÅäÖÃ
Clk_SetPeripheralGate(ClkPeripheralBt,TRUE);
Clk_SetPeripheralGate(ClkPeripheralUart0,TRUE);
stcUartIrqCb.pfnRxIrqCb = RxIntCallback;//½ÓÊÕÖжϺ¯ÊýÈë¿Ú
stcUartIrqCb.pfnTxIrqCb = NULL;//·¢ËÍÖжϺ¯ÊýÈë¿Ú
stcUartIrqCb.pfnRxErrIrqCb = ErrIntCallback;//½ÓÊÕ´íÎóÖжϺ¯ÊýÈë¿Ú
stcConfig.pstcIrqCb = &stcUartIrqCb;//ÖжϷþÎñº¯Êý
stcConfig.bTouchNvic = TRUE;//ÖжÏʹÄÜ
stcConfig.enRunMode = UartMode3;
stcMulti.enMulti_mode = UartNormal;//Õý³£Ä£Ê½
stcConfig.pstcMultiMode = &stcMulti;
//
// enTb8 = UartEven;
// Uart_SetMMDOrCk(UARTCH0,Even);//ÉèÖÃżУÑé
stcBaud.bDbaud = 0u;
stcBaud.u32Baud = 9600u;
stcBaud.u8Mode = UartMode3; //¼ÆË㲨ÌØÂÊÐèҪģʽ²ÎÊý
pclk = Clk_GetPClkFreq();
timer=Uart_SetBaudRate(UARTCH0,pclk,&stcBaud);
stcBtConfig.enMD = BtMode2;
stcBtConfig.enCT = BtTimer;
Bt_Init(TIM0, &stcBtConfig);//µ÷ÓÃbasetimer1ÉèÖú¯Êý²úÉú²¨ÌØÂÊ
Bt_ARRSet(TIM0,timer);
Bt_Cnt16Set(TIM0,timer);
Bt_Run(TIM0);
Uart_Init(UARTCH0, &stcConfig);
Uart_EnableIrq(UARTCH0,UartRxIrq);
Uart_ClrStatus(UARTCH0,UartRxFull);//Çå³ý½ÓÊÕ±ê־λ
Uart_EnableFunc(UARTCH0,UartRx);
}
/*******************************************************/
void Send_Data(void)
{
if(COMM_Struct.TxSendMark)
{
COMM_Struct.TxSendMark = 0;
for(u8 i=0;i<6;i++)
{
Dis();
Uart_SetTb8(UARTCH0,Even,COMM_Struct.TxBuff[i]);
Uart_SendData(UARTCH0,COMM_Struct.TxBuff[i]);
}
Uart_ClrStatus(UARTCH0,UartTxEmpty);
}
}
软件持续测试发送接收到的数组数据后,会出现接收数据和发送数据数组字节错位情况是什么原因。
比如接收数据是01 02 03 04 05 06
串口助手接收到的反馈数据是02 03 04 05 06 01
仿真时候看不出异常,比如仿真时候Uart_SendData(UARTCH0,COMM_Struct.TxBuff[i]);内COMM_Struct.TxBuff[i]数据为01,但是串口助手接收到的数据却是为06
单片机重启后运行是正常状态,只有在连续收发测试一段时间后会出现这种异常,是什么原因照成的?
|