1 Reply Latest reply on Jul 12, 2018 9:53 AM by msur

    PSoC63 How to correctly set Hibernate Mode - Device does never wake up

    andre.vaas_2417461

      Hi,

       

      I want to set the device in Hibernate mode and wake it up from RTC. The code works if I use deepsleep but not if I am using Hibernate. It just runs until it enters Hibernate. But it does never recover.

      Could you please support, whats wrong with the code? The RTC runs through the WCO and the WCO was set as clock source. The code shall set the RTC as wake up source which shall reset the chip every second.

       

      void Cy_RTC_Alarm1Interrupt(void)

      {

          /* Clear any pending interrupts */

          Cy_RTC_ClearInterrupt(CY_RTC_INTR_ALARM1);

          __NVIC_ClearPendingIRQ(RTC_RTC_IRQ_cfg.intrSrc);

      }

       

      /* Default time written to RTC at power-up or reset */

      #define TIME_AT_RESET           (00u),   /* Seconds    */\

                                      (00u),   /* Minutes    */\

                                      (00u),   /* Hours      */\

                                      (01u),   /* Date       */\

                                      (01u),   /* Month      */\

                                      (17u)    /* Year 20xx  */

       

      cy_stc_rtc_alarm_t const alarm =

      {

          .sec            =   01u,

          .secEn          =   CY_RTC_ALARM_ENABLE,

          .min            =   00u,

          .minEn          =   CY_RTC_ALARM_DISABLE,

          .hour           =   00u,

          .hourEn         =   CY_RTC_ALARM_DISABLE,

          .dayOfWeek      =   01u,

          .dayOfWeekEn    =   CY_RTC_ALARM_DISABLE,

          .date           =   01u,

          .dateEn         =   CY_RTC_ALARM_DISABLE,

          .month          =   01u,

          .monthEn        =   CY_RTC_ALARM_DISABLE,

          .almEn          =   CY_RTC_ALARM_ENABLE

      };

       

      cy_stc_syspm_callback_params_t callbackparams =

      {

          CY_SYSPM_CHECK_READY, 

          NULL,                        

          NULL                     

      };

       

       

      void InitRtc(void)

      {

          /* Start the RTC */

          RTC_Start(); 

         

          /* Clear any pending interrupts */

          Cy_RTC_ClearInterrupt(CY_RTC_INTR_ALARM1);

          __NVIC_ClearPendingIRQ(RTC_RTC_IRQ_cfg.intrSrc);

         

          /*Configures the source (Alarm1) that trigger the interrupts */

          Cy_RTC_SetInterruptMask(CY_RTC_INTR_ALARM1);

       

          /* Set the default date and time and wait till the operation is successful */

          while(Cy_RTC_SetDateAndTimeDirect(TIME_AT_RESET) != CY_RET_SUCCESS);

          

          /* Wait for alarm to be set */

          while(Cy_RTC_SetAlarmDateAndTime(&alarm,CY_RTC_ALARM_1) != CY_RET_SUCCESS);

      }

       

       

      int main(void)

      {

          __enable_irq(); /* Enable global interrupts. */

       

       

          //SystemInit();

         

          /* Place your initialization/startup code here (e.g. MyInst_Start()) */

          //Cy_BLE_Start(StackEventHandler);

          InitRtc();

         

          for(;;)

          {

              while(Cy_RTC_SetDateAndTimeDirect(TIME_AT_RESET) != CY_RET_SUCCESS);

              /* Place your application code here. */

              //Cy_BLE_ProcessEvents();

              Cy_GPIO_Clr(LEDB_0_PORT, LEDB_0_NUM);

              Cy_SysLib_Delay(100);

              Cy_GPIO_Set(LEDB_0_PORT, LEDB_0_NUM);

              Cy_SysLib_Delay(100);

              //Cy_RTC_DeepSleepCallback(&callbackparams);

             

              //Cy_RTC_HibernateCallback(&callbackparams);

              /* Set the wake-up signal from Hibernate */

              Cy_SysPm_SetHibWakeupSource(CY_SYSPM_HIBERNATE_RTC_ALARM);

             

              /* Jump into Hibernate */

              Cy_SysPm_Hibernate();

              //Cy_SysPm_DeepSleep(CY_SYSPM_WAIT_FOR_INTERRUPT);

          }

      }

       

      Thank you!