STM32 USART串口的学习与体会
时间:11-19
来源:互联网
点击:
annel; //选择串口1中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //抢占式中断优先级设置为0
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; //响应式中断优先级设置为0
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//使能中断
NVIC_Init(&NVIC_InitStructure);
}
然后在stm32f10x_it.c文件中找到相应的中断处理函数,并填入一下内容。注意在stm32f10x_it.c中,要声明一下外部变量RX_status
extern FlagStatus RX_status;
void USART1_IRQHandler(void)
{
GPIO_SetBits(GPIOB, GPIO_Pin_5);
//确认是否接收到数据
RX_status = USART_GetFlagStatus(USART1,USART_FLAG_RXNE);
//接收到数据
if(RX_status == SET)
{
//将数据回送至超级终端
USART_SendData(USART1, USART_ReceiveData(USART1));
//等待数据发送完毕
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) ==RESET);
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
}
}
STM32USAR 相关文章:
- stm32 USART_IT_IDLE(12-03)
- stm32学习之七(12-03)
- stm32学习之九(12-03)
- STM32中USART的DMA 实现(12-03)
- stm32的USART_IT_TXE和USART_IT_TC(12-03)
- STM32 USART 串口简单使用(12-01)