Initializing External Interrupt pin as wake up option for stop mode
Hi,
I am using the stm32L100RBT6 and I have successfully implemented the stop mode.
I have chosen to wake up the µC from stop mode either by RTC or by an external interrupt.
Before I put the µC in stop mode, I set all the pins to analog to save power and then I initialize the pins I am using for wake up in interrupt mode.
The first time the µC goes into stop mode, there is no problem with the initialization of the interrupt pins.
The problem arises in the initialization of the interrupt pins after the µC wakes up from stop mode by RTC.
In doing the initialization of the interrupt pins again, the interrupt pin is somehow enabled and it wakes the µC from stop mode immediately after it goes into stop mode.
My question is, what am I doing wrong in either the initialization of the pin as an interrupt or in disabling the interrupt pin when the µC wakes up by RTC?
Or what is the proper procedure to follow to initialize a pin in interrupt mode which will be used to wake the µC from stop mode?
I hope I was clear enough =)
Below are my codes:
Interrupt pins inititalisation
void wakeup_pins_init(void){
GPIO_InitTypeDef GPIO_InitStruct;
memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitStruct));
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = DISPLAY_BUTTON_1_Pin|DISPLAY_BUTTON_2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI0_IRQn, 1, 1);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
HAL_NVIC_SetPriority(EXTI1_IRQn, 1, 1);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
}stop mode enable function
void Stop_Mode_Enable(void){
HAL_SPI_DeInit(&spi2);
HAL_ADC_DeInit(&hadc);
HAL_UART_DeInit(&hsuart1);
HAL_I2C_DeInit(&i2c1);
HAL_UART_DeInit(&huart3);
Gpio_Pins_Disable();
wakeup_pins_init();
__HAL_RTC_WRITEPROTECTION_DISABLE(&my_rtc);
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&my_rtc,RTC_IT_WUT);
HAL_RTCEx_SetWakeUpTimer_IT(&my_rtc,10,RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
__HAL_RTC_WAKEUPTIMER_ENABLE_IT(&my_rtc,RTC_IT_WUT);
__HAL_RTC_WRITEPROTECTION_ENABLE(&my_rtc);
HAL_NVIC_SetPriority(RTC_WKUP_IRQn,0,0);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
HAL_PWREx_EnableUltraLowPower();
HAL_PWREx_DisableFastWakeUp();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON,PWR_STOPENTRY_WFE);
if( WakeUpSource == WAKE_UP_RTC){
after_stop_mode_init();
}
}Set all pins as analog function
void Gpio_Pins_Disable(void){
GPIO_InitTypeDef GPIO_InitStruct;
memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitStruct));
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_All;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_All & (~(GPIO_PIN_14 | GPIO_PIN_13));// leave debug pins active
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
}