AnsweredAssumed Answered

no interrupts in low power (STM32L151)

Question asked by Jesse Bax on Jan 18, 2018

Hello everyone,


I'm trying to make a device where the MCU (STM32L151) has to wake up periodically every 5 minutes and send a LoRa message. As such i want to put the device in a low power mode between messages. I read up on the datasheets and manuals on how to do this and decided to use the HAL. Now when i put the device to sleep it does not wake up anymore...


I would like to note that everything works perfectly when i use the "normal" power mode (ie. not touching any power settings).


I want the device to wakeup from either:

  • RTC alarm interrupt
    • the RTC alarm is set to every 5 minutes. the pin interrupt is connected to a switch that protects our module from people opening the case. 
  • Interrupt on pin PC13 (interrupt wakeup pin)
    • with a signal going from either high to low or low to high (so rising AND falling edge)



In the code below you can see i use HAL_PWR_EnterSLEEPMode. while the mcu enters the low power mode, it does not exit on the pin or RTC interrupt. I have also tried HAL_PWR_EnterSTOPMode() and HAL_PWR_EnterStandbyMode(), but the result stays the same.



while (1) {
//if device is open when battery is just inserted the device has to wait till case is closed
if (caseprotector_get_state() >= closed_protected) {
/* run the LoRa class A state machine*/


   if (lora_getDeviceState() == DEVICE_STATE_SLEEP) {





Code for initializing the interrupt pin (PC13):

void MX_GPIO_Init(void)

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */

/*Configure GPIO pin Output Level */



/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = Security_Switch_Pin;
HAL_GPIO_Init(Security_Switch_GPIO_Port, &GPIO_InitStruct);



/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);


Initializing the RTC:


* @brief Configures the RTC timer
* @note The timer is based on the RTC
* @param none
* @retval none
static void HW_RTC_SetConfig( void )
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;

RtcHandle.Instance = RTC;

RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RtcHandle.Init.AsynchPrediv = PREDIV_A; /* RTC_ASYNCH_PREDIV; */
RtcHandle.Init.SynchPrediv = PREDIV_S; /* RTC_SYNCH_PREDIV; */
RtcHandle.Init.OutPut = RTC_OUTPUT;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

HAL_RTC_Init( &RtcHandle );

/*Monday 1st January 2016*/
RTC_DateStruct.Year = 16;
RTC_DateStruct.Date = 1;
HAL_RTC_SetDate(&RtcHandle , &RTC_DateStruct, RTC_FORMAT_BIN);

/*at 0:0:0*/
RTC_TimeStruct.Hours = 0;
RTC_TimeStruct.Minutes = 0;

RTC_TimeStruct.Seconds = 0;
RTC_TimeStruct.TimeFormat = 0;
RTC_TimeStruct.SubSeconds = 0;
RTC_TimeStruct.StoreOperation = RTC_DAYLIGHTSAVING_NONE;

HAL_RTC_SetTime(&RtcHandle , &RTC_TimeStruct, RTC_FORMAT_BIN);

/*Enable Direct Read of the calendar registers (not through Shadow) */

Lastly i would like to add that i don't have a lot of experience with the ST MCU's. 

I hope someone can help me with this problem.


If you have further questions please ask them, i'll be happy to answer them!


Kind regards,

Jesse Bax,

Jr software developer