1. 程式人生 > >STM32F401 外部中斷誤觸發問題

STM32F401 外部中斷誤觸發問題

stm32f401 cfg onf cmd mcu nvic 現象 ports nbsp

現象:調試STM32F411低功耗的時候,使用的PA1做個喚醒源,發現在沒有觸發EXTI的時候,MCU居然被喚醒。

原因:PA1配置成EXTI(上拉輸入),經常被誤觸發

解決方式:將PA1配置成浮空輸入,並且外部上拉一個4.7k電阻,就不會誤觸發了。

這種bug的原因一直沒有搞清,先記下省的以後就忘記了,猜測可能是STM32芯片bug。

EXTI配置代碼如下:

void TM_SetExit(FunctionalState State)
{
//PA1
#define REQUEST_PORT GPIOA
#define REQUEST_PIN GPIO_Pin_1
#define REQUEST_CLK_BUS RCC_AHB1Periph_GPIOA
#define REQUEST_PORT_SRC EXTI_PortSourceGPIOA
#define REQUEST_PIN_SRC GPIO_PinSource1
#define REQUEST_EXTI_LINE EXTI_Line1
#define REQUEST_NVIC_CHANNEL EXTI1_IRQn

GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;

RCC_AHB1PeriphClockCmd(REQUEST_CLK_BUS, ENABLE);
GPIO_InitStructure.GPIO_Pin = REQUEST_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd_UP;
GPIO_Init(REQUEST_PORT, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(REQUEST_PORT_SRC, REQUEST_PIN_SRC);

NVIC_InitStructure.NVIC_IRQChannel = REQUEST_NVIC_CHANNEL;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = State;
NVIC_Init(&NVIC_InitStructure);

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_LineCmd = State;
EXTI_InitStructure.EXTI_Line = REQUEST_EXTI_LINE;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(REQUEST_EXTI_LINE);
}

STM32F401 外部中斷誤觸發問題