用USART1进行串口收发数据,始终收不到数据,mcu始终处于闲的状态,我初始化的代码 和main函数代码在下面,望大神指教到底是啥问题???
void Usart_Configura
tion(uint32_t BaudRate)
{
USART_InitTypeDef USART_InitStructure; //定义一个串口结构体
USART_InitStructure.USART_BaudRate =BaudRate ; //波特率115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //传输过程中使用8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1; //在帧结尾传输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(USART1, &USART_InitStructure); //根据参数初始化串口寄存器
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //使能串口中断接收
USART_Cmd(USART1, ENABLE); //使能串口外设
}
int main(void)
{
SystemInit(); //系统时钟配置
Init_LED(); //各个外设引脚配置
Init_Usart(); //串口引脚配置
Usart_Configuration(115200); //串口配置 设置波特率为115200
while(1)
{
printf("%d",USART1_Receive_Byte());
}
void Init_NVIC(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
不知道是哪里的问题始终不进中断??
一周热门 更多>