3195 views|2 replies

3184

Posts

0

Resources
The OP
 

STM32L151C8T6 cannot enter serial port interrupt [Copy link]

我写了一个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;                                       
        }
}

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

This post is from stm32/stm8

Latest reply

Interrupt is not enabled  Details Published on 2019-5-27 08:50
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 

1059

Posts

1

Resources
2
 
Interrupt is not enabled
This post is from stm32/stm8
 
 

3184

Posts

0

Resources
3
 
Thank you! Just add this sentence. USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //Receive interrupt enable
This post is from stm32/stm8
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list