// LSB to MSB //
for(u8 i=0;i<8;i++)
{
if(TxData&0x80)
tx|=0x80;
if(i!=7)tx>>=1;
TxData<<=1;
}
/* Loop while DR register in not emplty */
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) //发送缓存标志位为空
{
retry++;
if(retry>200)return 0;
}
/* Send tx */
USART_SendData(USART2, tx); //发送一个数据
/* Wait to receive a byte */
while (USART_GetFlagStatus(USART2,USART_FLAG_RXNE) == RESET) //接收缓存标志位不为空
{
}
// Return the byte read from the SPI bus
/* 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);