[STM32L1]

stm32l151c8t6串口中断进不去

[复制链接]
833|3
手机看帖
扫描二维码
随时随地手机跟帖
Cjy_JDxy|  楼主 | 2019-5-27 08:27 | 显示全部楼层 |阅读模式
我写了一个STM32L151C8T6串口中断的程序,如下:
USART_InitTypeDef USART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
       
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);        //使能USART1
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);        //GPIOA时钟

       
    delay_init(32);
         //USART1_TX   PA9
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;       
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    //USART1_RX          PA10
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
               
        USART_DeInit(USART1);  //复位串口1


        GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);


    USART_InitStructure.USART_BaudRate = 38400;
    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_Cmd(USART1,ENABLE);

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/* Enable the usart1 Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
//串口1接收中断
void USART1_IRQHandler(void)                        //串口1中断服务程序
{
       
       
//        if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)                                //是否接收中断发生,使用库函数
        if ((USART1->CR1 & (1 << 5)) && (USART1->SR & (1 << 5)))                //是否接收中断发生,使用寄存器
        {

                Receive_Buffer[Receive_Cnt++] = USART_ReceiveData(USART1);                        //读取串口接收数据
               
                if(Receive_Cnt >= 600) Receive_Cnt = 0;                                                                                                        //判断缓冲区是否已满               
               
                ReceiveTime = 2;                                       
        }
}

发现进不了中断,各位大神看看,哪里有问题?谢谢!

使用特权

评论回复
buffered| | 2019-5-27 16:57 | 显示全部楼层
中断配置与中断允许再检查一下

使用特权

评论回复
Cjy_JDxy|  楼主 | 2019-5-27 17:05 | 显示全部楼层
谢谢!加上这句好了。
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);                                //接收中断使能

使用特权

评论回复
wowu| | 2019-6-17 14:48 | 显示全部楼层
天哪 低级错误

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:绿水本无忧因风皱面,青山原不老为雪白头。

553

主题

3520

帖子

19

粉丝