从PC键盘上往板子的COM0送字符,并将COM0收到字符再传回超级终端显示,但现在超级终端没显示输入的字符,只显示原来printf的字符?麻烦大家看看哪错了,谢谢
板子是万利的199元的那块板子
程序大致如下:
int main(void)
{
u16 i=0;
#ifdef DEBUG
debug();
#endif
/* System Clocks Configuration */
RCC_Configuration();
/* GPIO Configuration */
GPIO_Configuration();
/* NVIC configuration */
NVIC_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_Configuration();
printf("\r\n PLEASE INPUT CHARACTER FROM KEYBOAD \r\n");
while (1)
{
if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)
{
i= USART_ReceiveData(USART1);
printf(" %c",i&0xFF);
}
}
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef 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_Even;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_ClockInitStructure.USART_Clock=USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL=USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA=USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit=USART_LastBit_Disable;
USART_Init(USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);
}
/*将C库中prinf函数重定向到USART*/
int fputc(int ch,FILE *f)
{
USART_SendData(USART1,(u8)ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET)
{
}
return ch; |