野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 15404|回复: 5

串口中断问题 求解答

[复制链接]
发表于 2015-5-13 18:30:54 | 显示全部楼层 |阅读模式
串口中断问题  
int main (void)
{
  I2C_EE_Init();               
  /* 串口1初始化 */
  USART1_Config();
NVIC_Configuration();
while(1)
{   
            ADC_1();
            ADC_2();
            ADC_3();
                  ADC_11();
            ADC_12();       
        }

}
做了一个串口中断来判断数组,但是为什么中断完了之后,没有继续循环WHILE循环?
哪位高手告诉下!

void USART1_IRQHandler(void)//读取串口的数据
{
          u8  c;
       
        if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
        {        
           c=USART1->DR;
                 
        if(i<10)
        {
                  a[i]=USART_ReceiveData(USART1);
                    i++;
                }
                 if(i==9)
                 {
                        USART1_1();
                        USART1_2();
                       
                        i=0;
       }
          printf("%c",c);    //将接受到的数据直接返回打印
       
   }
        }


         

回复

使用道具 举报

发表于 2015-5-13 18:58:54 | 显示全部楼层
退出中断服务程序之前要清中断标志位,参考例程的中断服务程序编写方法
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-13 19:50:26 | 显示全部楼层
亽亼 发表于 2015-5-13 18:58
退出中断服务程序之前要清中断标志位,参考例程的中断服务程序编写方法

恩 我看下
**********************************************************************************/
#include "usart1.h"
#include <stdarg.h>
#include "misc.h"

/*
* 函数名:USART1_Config
* 描述  :USART1 GPIO 配置,工作模式配置。115200 8-N-1
* 输入  :无
* 输出  : 无
* 调用  :外部调用
*/
void USART1_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
       
        /* config USART1 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
       
        /* USART1 GPIO config */
        /* Configure USART1 Tx (PA.09) as alternate function push-pull */
        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);   
        /* Configure USART1 Rx (PA.10) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
          
        /* USART1 mode config */
        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_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);
}


void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        /* Configure the NVIC Preemption Priority Bits */  
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
       
        /* Enable the USARTy Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQHandler;         
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}
/*
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-29 00:39:57 | 显示全部楼层
亽亼 发表于 2015-5-13 18:58
退出中断服务程序之前要清中断标志位,参考例程的中断服务程序编写方法

没有找到库文件的清除标示位,再想是不是,库不完整?用的野火的3.5的库
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-29 00:40:21 | 显示全部楼层
本帖最后由 侯希白 于 2015-5-29 00:42 编辑
亽亼 发表于 2015-5-13 18:58
退出中断服务程序之前要清中断标志位,参考例程的中断服务程序编写方法


看Stm32手册发现的问题?
回复 支持 反对

使用道具 举报

发表于 2015-5-29 08:59:52 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-20 17:57 , Processed in 0.051042 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表