{ /* USART2 configuration ------------------------------------------------------*/ /* USART2 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control enabled (RTS and CTS signals) - Receive and transmit enabled - USART Clock disabled - USART CPOL: Clock is active low - USART CPHA: Data is captured on the second edge - USART LastBit: The clock pulse of the last data bit is not output to the SCLK pin */ 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_RTS_CTS; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_Clock = USART_Clock_Disable; USART_InitStructure.USART_CPOL = USART_CPOL_High;//USART_CPOL_Low; USART_InitStructure.USART_CPHA = USART_CPHA_2Edge; USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
USART_Init(USART2, &USART_InitStructure);//////这个地方参数可以传入,但发现写到寄存器,写完了没看到反应,还是显示为000,所以我怀疑是不是A版的IC有些问题,因为当前的IC听香主说也没有ISP功能, /* Enable the USART2 */ USART_Cmd(USART2, ENABLE);
/* Communication hyperterminal-USART2 using hardware flow control -------------*/ /* Send a buffer from USART to hyperterminal */ while(NbrOfDataToTransfer--) { USART_SendData(USART2, TxBuffer[TxCounter++]); while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); /////走到这就再也走不下去了,因为寄存器一直为0 }
/* Receive a string (Max RxBufferSize bytes) from the Hyperterminal ended by '\r' (Enter key) */ do { if((USART_GetFlagStatus(USART2, USART_FLAG_RXNE) != RESET)&&(RxCounter < RxBufferSize)) { RxBuffer[RxCounter] = USART_ReceiveData(USART2); USART_SendData(USART2, RxBuffer[RxCounter++]); } }while((RxBuffer[RxCounter - 1] != '\r')&&(RxCounter != RxBufferSize));