在串口初始化中开启了接收中断,通过调试助手给串口1发送一个字节之后就老是进入串口接收中断函数,可是在串口的中断函数中清除了接收中断标志位了啊,不知道这是怎么一回事啊?请大神们指点。
串口初始化代码:
- void Uart1Init( uint32 Bps )
- {
- OS_CPU_SR cpu_sr;
- OS_ENTER_CRITICAL();
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8; //PA8/RS485EN_1
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//输出
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9; //PA9_uart1_TX
- 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; //PA10 USART1_RX
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//悬空输入
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//只有串口1 使用72M,其他串口使用36M
- USART_InitTypeDef USART_InitStructure;
- //串口参数配置:9600,8,1,无奇偶校验,无硬流量控制 ,使能发送和接收
- USART_InitStructure.USART_BaudRate = Bps; //设置波特率
- 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); //初始化串口3
-
- USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //使能发送、接收中断
- USART_Cmd(USART1, ENABLE); //使能串口2
-
- // St2Pt_EN();//RS485使能 ST输出到Pt //发送模式
- Pt2St_EN(); //Rs485 使能PT输出到St //接收模式
- OS_EXIT_CRITICAL();
- }
- void Uart1_SendByte(unsigned char dat)
- {
- USART_SendData(USART1,dat); //发送8位字符数据
- while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);//查询发送数据寄存器空标志,等待发送完毕
- }
|