qihao74 发表于 2022-1-24 11:20

stop模式下,串口的RX引脚配置为外部中断模式,为什么会马上引起中断

stop模式下,串口的RX引脚配置为外部中断模式,为什么会马上引起中断
关闭串口后,已经HAL_Delay(1);才设置外部中断模式

香水城 发表于 2022-1-24 11:54

你在使能相应外部中断之前,不妨先做个对相应中断标志位清零的操作看看?

qihao74 发表于 2022-1-24 15:06

香水城 发表于 2022-1-24 11:54
你在使能相应外部中断之前,不妨先做个对相应中断标志位清零的操作看看?

...

清标志还是会进中断

qihao74 发表于 2022-1-24 15:07

/******************************************************************************/
void LPUART_Config1(void)                                        //标定20200612
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        GPIO_InitStructure.Pin = PA4_NBRST;
        GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
        GPIO_InitStructure.Pull = GPIO_PULLUP;
        HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
        HAL_GPIO_WritePin(GPIOA, PA4_NBRST,GPIO_PIN_RESET);        //TCS=0       20220110
       
       /* UART configured as follows:
      - Word Length = 8 Bits
      - Stop Bit = One Stop bit
      - Parity = None
      - BaudRate = 9600 baud
      - Hardware flow control disabled (RTS and CTS signals) */       
        HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11|GPIO_PIN_10);
               
        LPUartHandle.Instance      = LPUART1;
        HAL_UART_DeInit(&LPUartHandle);   //复位串口
       
        //LPUartHandle.Init.BaudRate   = 9600;
        BaudRate_Config(Baud_Rate);        //波特率设置        //20220117
LPUartHandle.Init.WordLength = UART_WORDLENGTH_8B;                //字长为 8 位
LPUartHandle.Init.StopBits   = UART_STOPBITS_1;       //一个停止位
LPUartHandle.Init.Parity   = UART_PARITY_NONE;      //无奇偶校验位
LPUartHandle.Init.HwFlowCtl= UART_HWCONTROL_NONE;   //无硬件数据流控制
        //LPUartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
LPUartHandle.Init.Mode       = UART_MODE_TX_RX;       //收发模式
if(HAL_UART_Init(&LPUartHandle) != HAL_OK)
{
    Error_Handler();                                    //初始化串口
}
        /* Enable the UART Data Register not empty Interrupt */
HAL_UART_Receive_IT(&LPUartHandle,&LPRxBuffer, 1);//开中断接收
}
/**********************************************************************
函数名称:uart_exit_init
函数功能: RX引脚配置为外部中断
入口:                                                   
出口:
备注:
**********************************************************************/
void uart_exit_init(void)
{
        /*
       __HAL_UART_DISABLE_IT(&Uart2Handle, UART_IT_RXNE); //20200703
       HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
   HAL_UART_DeInit(&Uart2Handle);
   
   
   
   GPIO_InitStructure.Pin = GPIO_PIN_2|GPIO_PIN_3;   //配置PA2、PA3为输入口
   GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
   GPIO_InitStructure.Pull = GPIO_NOPULL;

   HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
   
   __HAL_RCC_GPIOA_CLK_ENABLE(); //使能(开启)引脚对应IO端口时钟
       */
       __HAL_UART_DISABLE_IT(&LPUartHandle, UART_IT_RXNE);//20200612
       HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11|GPIO_PIN_10);
   HAL_UART_DeInit(&LPUartHandle);         //复位串口
       
       HAL_Delay(1);
       
       GPIO_InitTypeDef   GPIO_InitStructure;
       
   GPIO_InitStructure.Pin = GPIO_PIN_10;   //配置PB10为输入口
   GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
   GPIO_InitStructure.Pull = GPIO_NOPULL;

   HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
   
    __HAL_RCC_GPIOB_CLK_ENABLE(); //使能(开启)引脚对应IO端口时钟
   
   GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;//配置PB11为外部中断脚
   GPIO_InitStructure.Pull = GPIO_NOPULL; //GPIO_NOPULL 20220121
   GPIO_InitStructure.Pin = GPIO_PIN_11;//20200522
   GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
   HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
   
       __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_11);
       
   /* Enable and set EXTI4_15 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

/* Enable and set EXTI0_11 Interrupt to the highest priority */
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
}
/******************************************************************************/
void EXTI4_15_IRQHandler(void)
{
          // EXTI line interrupt detected

if(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_11) != RESET)
{
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_11);
                               
    SystemClock_Config();       
    LPUART_Config1();                //标定20200612
}
}

bioe 发表于 2022-1-25 08:22

从代码中看到PB11配置为下降沿中断,进入外部中断说明PB11引脚出现下降沿信号,如果连接了电脑串口,可以将串口拔掉试试,排除来自电脑串口的下降沿信号

qihao74 发表于 2022-1-25 09:51

bioe 发表于 2022-1-25 08:22
从代码中看到PB11配置为下降沿中断,进入外部中断说明PB11引脚出现下降沿信号,如果连接了电脑串口,可以将 ...

串口什么都没接,PB11也设为上拉,也会马上中断

ayb_ice 发表于 2022-1-25 10:50

qihao74 发表于 2022-1-25 09:51
串口什么都没接,PB11也设为上拉,也会马上中断

哪有中断PIN配置为模拟口的,一般输入且上拉

ayb_ice 发表于 2022-1-25 11:13

多开了一个中断吧,另外测试时先断开外部连接再测试

qihao74 发表于 2022-1-25 14:39

问题找到了
原因是PB11配置为下降沿中断,会导致口线跳变,马上引起中断

qihao74 发表于 2022-1-25 14:42

void uart_exit_init(void)
{

         __HAL_UART_DISABLE_IT(&LPUartHandle, UART_IT_RXNE);//20200612
         HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11|GPIO_PIN_10);
   HAL_UART_DeInit(&LPUartHandle);         //复位串口
      
      
      
         GPIO_InitTypeDef   GPIO_InitStructure;
      
   GPIO_InitStructure.Pin = GPIO_PIN_10;   //配置PB10为输入口
   GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
   GPIO_InitStructure.Pull = GPIO_NOPULL;

   HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
   
    __HAL_RCC_GPIOB_CLK_ENABLE(); //使能(开启)引脚对应IO端口时钟
   
   GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;//配置PB11为外部中断脚
   GPIO_InitStructure.Pull = GPIO_PULLUP; //GPIO_NOPULL 20220121
   GPIO_InitStructure.Pin = GPIO_PIN_11;//20200522
    //GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
   HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);

    HAL_Delay(1);

         __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_11);
         
   /* Enable and set EXTI4_15 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

}

qihao74 发表于 2022-1-25 14:45

延时再清中断标志

redone 发表于 2022-1-26 10:16

qihao74 发表于 2022-1-25 14:39
问题找到了
原因是PB11配置为下降沿中断,会导致口线跳变,马上引起中断

下降沿,为什么会引起跳变

qihao74 发表于 2022-1-26 16:48

我串口是接485模块,用示波器测发现的,PB11配置为下降沿中断,就会导致口线跳变
页: [1]
查看完整版本: stop模式下,串口的RX引脚配置为外部中断模式,为什么会马上引起中断