stm32串口中断1能进去,中断2进不去

2019-07-14 15:20发布

/****系统外设时钟设置***
void Clock_Peripheral_Init()
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);//
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_tiM2,ENABLE);//
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//        
}
/****I/O初始化*****
void GPIO_Configuration()
{
  GPIO_InitTypeDef GPIO_InitStructure;
        //GPIOA
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  
        GPIO_Init(GPIOA, &GPIO_InitStructure);//
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
        GPIO_Init(GPIOA, &GPIO_InitStructure);//        
}
/***UART1初始化*****
void UART1_Configuration()
{
        USART_InitTypeDef USART_InitStructure;
        USART_InitStructure.USART_BaudRate = 19200;
        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_ITConfig(USART1, USART_IT_RXNE, ENABLE);//ʹÄܽÓÊÕÖÐÏ
        USART_Cmd(USART1, ENABLE);//´®¿Ú1ÍâÉèʹÄÜ
}
/***UART2初始化****
void UART2_Configuration()
{
        USART_InitTypeDef USART_InitStructure;
        USART_InitStructure.USART_BaudRate = 4800;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_Even;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
        USART_Init(USART2, &USART_InitStructure);

        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART2, ENABLE);
}
/***定时器2配置****
void TIM2_Configuration(void)
{
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        TIM_DeInit(TIM2); //³õʼ»¯ÎªÈ±Ê¡Öµ
        TIM_TimeBaseStructure.TIM_Period=1000;        
        TIM_TimeBaseStructure.TIM_Prescaler= (72 - 1);
        TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV        TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;         TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
        TIM_ClearFlag(TIM2, TIM_FLAG_Update);                TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
        TIM_Cmd(TIM2, ENABLE);
}
/****优先级*****
void NVIC_Configuration()
{
        NVIC_InitTypeDef NVIC_InitStructure;
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);                                                                                                        
        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;//TIME2         
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;//ÏÈÕ¼ÓÅÏȼ¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);        

        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);        
}
<p>
0条回答

一周热门 更多>