附官方 同步模式主要程序!
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USARTy TX and USARTy CK pins as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = USARTy_TxPin | USARTy_ClkPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
/* Configure USARTy RX as input floating */
GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | SPIy_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
/* Enable USARTy Clock */
RCC_APB2PeriphClockCmd(USARTy_CLK, ENABLE);
USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
USART_ClockInit(USARTy, &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USARTy, &USART_InitStructure);
/* Configure the USARTy */
USART_Init(USARTy, &USART_InitStructure);
/* Enable the USARTy */
USART_Cmd(USARTy, ENABLE);
USART_SendData(USARTy, DYMMY_BYTE);
while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET)
{
}
/* Wait the byte is entirely received by USARTy */
while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET)
{
}
/* Store the received byte in the RxBuffer1 */
RxBuffer1[RxCounter1++] = USART_ReceiveData(USARTy);