大神帮我看看,这个串口在keil不报错,可是在串口助手中没法接收数据,大神帮我看看哪里有问题
#include "stm32f10x_conf.h"
#include "stm32f10x_usart.h"
void usart_init (void)
{
//定义参数
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//使能及复用时钟
RCC_APB2PeriphClockCmd (//RCC_APB2Periph_AFIO| //串口重映射功能PB10 PB11
RCC_APB2Periph_GPIOA|
RCC_APB2Periph_USART1,ENABLE);
//PA9复用推挽50M输出 PA10上拉输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//PA10 上拉输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//串口复位
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
//串口初始化结构体
USART_InitStructure.USART_BaudRate =9600;
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_Tx|USART_Mode_Rx);
USART_Init(USART1,&USART_InitStructure);
//串口整体使能
USART_Cmd(USART1, ENABLE);
}
char data;
void usart_senddata (char data)
{
USART_SendData(USART1, data);
}
char usart_receive (void)
{
data=USART_ReceiveData(USART1);
return data;
}
#include "stm32f10x_conf.h"
//#include "stm32f10x_rcc.h"
#include "USART.H"
#include "stm32f10x_usart.h"
extern char data;
int main (void)
{
usart_init ();
while(1)
{
usart_senddata (usart_receive());
}
}
|