移植的官网的UART串口波特率自适应的例程,主要在
INT8U AutoBaudRate_StartBitMethod(void)
{
INT8U lubResult = 0;
static INT8U lubTaskID = 0;
switch(lubTaskID)
{
case 0:
{
/* Configure the AutoBaudRate method */
USART_AutoBaudRateConfig(cCOM1, USART_AutoBaudRate_StartBit);
/* Enable AutoBaudRate feature */
USART_AutoBaudRateCmd(cCOM1, ENABLE);
/* Wait until Receive enable acknowledge flag is set */
while(USART_GetFlagStatus(cCOM1, USART_FLAG_REACK) == RESET);
/* Wait until Transmit enable acknowledge flag is set */
while(USART_GetFlagStatus(cCOM1, USART_FLAG_TEACK) == RESET);
lubTaskID = 1;
break;
}
case 1:
{
/* Loop until the end of Autobaudrate phase */
if(USART_GetFlagStatus(cCOM1, USART_FLAG_ABRF) != RESET)
lubTaskID = 2;
break;
}
case 2:
{
/* If AutoBaudRate error occurred */
if(USART_GetFlagStatus(cCOM1, USART_FLAG_ABRE) == RESET)
{
/* Wait until RXNE flag is set */
while(USART_GetFlagStatus(cCOM1, USART_FLAG_RXNE) == RESET);
/* Wait until TXE flag is set */
while(USART_GetFlagStatus(cCOM1, USART_FLAG_TXE) == RESET);
/* Send received character */
USART_SendData(cCOM1, USART_ReceiveData(cCOM1));
/* clear the TE bit */
//USART_DirectionModeCmd(cCOM1, USART_Mode_Tx, DISABLE);
/* Check the Transfer Complete Flag */
while(USART_GetFlagStatus(cCOM1, USART_FLAG_TC) == RESET);
}
/* Disable AutoBaudRate feature */
USART_AutoBaudRateCmd(cCOM1, DISABLE);
/* Disable USART */
USART_Cmd(cCOM1, DISABLE);
lubResult = 1;
break;
}
default:
break;
}
return (lubResult);
}
|