cancel
Showing results for 
Search instead for 
Did you mean: 

Code gets stuck after enableInterrupts() and it does not function as per the logic.

ASing.20
Associate II

#include "stm8l15x.h"

#include "stm8l15x_gpio.h"

#include "stm8l15x_exti.h"

#include "stm8l15x_rtc.h"

#include "stm8l15x_itc.h"

#include "stm8l15x_clk.h"

#define WAKEUP_GPIO_PORT    GPIOE

#define WAKEUP_GPIO_PORT    GPIOE

#define ICC_WAKEUP_GPIO_PIN   GPIO_Pin_6

static void RTC_Config(void)

{

 /* Configures the RTC */

 CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);

 CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);

  

 RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);

 RTC_ITConfig(RTC_IT_WUT, ENABLE);

 /* Enable Interrupts*/

  

}

void Delay(__IO uint32_t nCount)

{

 for (; nCount != 0; nCount--);

}

void main(void)

{

 GPIO_Init(GPIOC, GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Slow);

GPIO_Init( WAKEUP_GPIO_PORT, ICC_WAKEUP_GPIO_PIN, GPIO_Mode_In_FL_IT);

/* Enable Rising edge port PE6 for wake up conter */

 EXTI->CR2 = 0x10; 

  /* RTC configuration -------------------------------------------*/

 RTC_Config();

enableInterrupts();

 /* Infinite loop */

 while (1)

 {

  GPIO_SetBits(GPIOC, GPIO_Pin_7);

  //Delay(0xFFFF);

   

  /* RTC will wake-up from halt every 5second */

  RTC_SetWakeUpCounter(5);

  RTC_WakeUpCmd(ENABLE);

  /* Enter Wait for interrupt mode*/

  wfi();

GPIO_ResetBits(GPIOC, GPIO_Pin_7);

Delay(60000);

  RTC_WakeUpCmd(DISABLE);

 }

}

2 REPLIES 2
AA1
Senior III

After enable Interrupts, an interrupt occurs if any is active. Where is the ISR?

And don't try to wakeup with GPIO and RTC at same time. Use just one, simplify you code.

ASing.20
Associate II

Thanks, I got the solution.

I was not using ISR after the interrupt that's why it used to get stuck.

I have changed the ISR and now it's working fine.