oceane 发表于 2018-3-31 10:56:41

STM32L152串口接受不进中断问题

用STM32L152系列单片机串口3(PD8(TX)、PD9(RX))调试模块,串口助手可接受到返回数据,但去进不接受中断不知道哪里配置错了,还是什么原因,大神帮忙看一下。(使用的是STM32L1xx_StdPeriph_Lib_V1.3.1版本库函数)
void sim_usart3_init(void)    // USART3、中断服务配置
        {
          GPIO_InitTypeDef GPIO_InitStructure;
                USART_InitTypeDef USART_InitStructure;
                NVIC_InitTypeDef NVIC_InitStructure;
//                NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
                RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);       
                RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
                       
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_Init(GPIOD, &GPIO_InitStructure);
                       
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_Init(GPIOD, &GPIO_InitStructure);
               
                GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_USART3);
                GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_USART3);

                NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
                NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;
                NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;               
                NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;       
                NVIC_Init(&NVIC_InitStructure);       
               
                USART_InitStructure.USART_BaudRate = 9600;
                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(USART3, &USART_InitStructure);
                USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//¿ªÆô´®¿Ú½ÓÊÜÖжÏ
                USART_Cmd(USART3, ENABLE);
        }
void USART3_IRQHandler(void)
        {
                u8 Resim = 0;
                if(USART_GetITStatus(USART3,USART_IT_RXNE) != RESET)
                {
                        USART_ClearITPendingBit(USART3,USART_IT_RXNE);
                        USART_RX_BUF3 = USART_ReceiveData(USART3);
                }       
        }

发表于 2018-3-31 11:12:35

P9也要和P9配置一样,用AF功能。

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_Init(GPIOD, &GPIO_InitStructure);

bargagebaobei 发表于 2018-3-31 13:29:21

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);

MrJiu 发表于 2018-3-31 13:42:54

我觉得最重要的是,你先用示波器看一下。。。确认波形数据OK先,在去确认软件上的事情!!!
页: [1]
查看完整版本: STM32L152串口接受不进中断问题