DA14531 DeepSleep

I am using DA14531MOD with SDK6

I am writing a program to make the microcomputer sleep with reference to this Website.

11. スリープモード — DA145XX チュートリアル SDK はじめに

This Website uses extended sleep on the microcomputer, but how can I use deep sleep?

  • Hi Yoshihiko,

    Thank you for posting your questions online.

    You can refer to this tutorial for applying the deep sleep:

    DA1453x & DA1458x Sleep Modes Tutorial — DA1453x & DA1458x Tutorial Sleep Modes

    Any further questions are welcome.

    BR,

    JH_Renesas

  • Thank you for your replying.

    I tried with your advice.

    I want to wake up the microcomputer from sleep with RTC.
    When the microcomputer wakes up, I want to execute the program from the middle, but the program is executed from the beginning.

    The programs are as follows

    static void configure_rtc_wakeup(void)
    {
    rtc_time_t alarm_time;

    // Init RTC
    rtc_reset();

    // Configure the RTC clock; RCX is the RTC clock source (14420 Hz)
    rtc_clk_config(RTC_DIV_DENOM_1000, 14420);
    rtc_clock_enable();

    rtc_config_t cfg = {.hour_clk_mode = RTC_HOUR_MODE_24H, .keep_rtc = 0};

    rtc_time_t time = {.hour_mode = RTC_HOUR_MODE_24H, .pm_flag = 0, .hour = 11,
    .minute = 55, .sec = 30, .hsec = 00};

    // Alarm interrupt in ten seconds
    alarm_time = time;
    alarm_time.sec += 5;

    // Initialize RTC, set time and data, register interrupt handler callback function and enable seconds interrupt
    rtc_init(&cfg);

    // Start RTC
    rtc_set_time_clndr(&time, NULL);
    rtc_set_alarm(&alarm_time, NULL, RTC_ALARM_EN_SEC);

    // Clear pending interrupts
    rtc_get_event_flags();
    rtc_register_intr(user_app_adv_restart, RTC_INTR_ALRM);
    }

    void user_app_adv_undirect_complete(const unsigned char a)
    {
    // update BLE data
    my_counter++;
    if(my_counter > 9) my_counter = 0;

    // deep sleep
    // Ensure PD_TIM is open
    SetBits16(PMU_CTRL_REG, TIM_SLEEP, 0);
    // Wait until PD_TIM is opened
    while ((GetWord16(SYS_STAT_REG) & TIM_IS_UP) != TIM_IS_UP);

    configure_rtc_wakeup();

    //app_easy_timer(ADV_SLEEP_TIME, user_app_adv_restart);
    arch_set_deep_sleep(PD_SYS_DOWN_RAM_ON, PD_SYS_DOWN_RAM_ON, PD_SYS_DOWN_RAM_ON, false);
    }

  • HI Yoshihiko,

    Thank you for the reply.
    Please refer on our prox_reporter where the Deep Sleep mode is implemented.
    You can have the 3 RAM blocks retained during Deep Sleep. After waking-up you should start from the RTC callback. Inside the RTC callback you should re-initialize the BLE core and the peripheral blocks. 
    After the initialization you can continue executing the code.
    Instead of declaring the user_app_adv_restart as the RTC callback, declare another callabck as shown in prox_reporter example.

    Best Regards,
    OV_Renesas

  • I modified the program using prox_reportar as a guide.
    But after sleep, the program starts over.
    What's wrong with me?

    void user_app_adv_undirect_complete(const unsigned char a)
    {

    // update BLE data
    my_counter++;
    if(my_counter > 9) my_counter = 0;

    // deep sleep
    // Ensure PD_TIM is open
    SetBits16(PMU_CTRL_REG, TIM_SLEEP, 0);
    // Wait until PD_TIM is opened
    while ((GetWord16(SYS_STAT_REG) & TIM_IS_UP) != TIM_IS_UP);

    configure_rtc_wakeup();

    //app_easy_timer(ADV_SLEEP_TIME, user_app_adv_restart);
    arch_set_deep_sleep(PD_SYS_DOWN_RAM_ON, PD_SYS_DOWN_RAM_ON, PD_SYS_DOWN_RAM_ON, false);

    }


    static void configure_rtc_wakeup(void)
    {

    rtc_time_t alarm_time;

    // Init RTC
    rtc_reset();

    // Configure the RTC clock; RCX is the RTC clock source (14420 Hz)
    rtc_clk_config(RTC_DIV_DENOM_1000, 14420);
    rtc_clock_enable();

    rtc_config_t cfg = {.hour_clk_mode = RTC_HOUR_MODE_24H, .keep_rtc = 0};

    rtc_time_t time = {.hour_mode = RTC_HOUR_MODE_24H, .pm_flag = 0, .hour = 11,
    .minute = 55, .sec = 30, .hsec = 00};

    // Alarm interrupt in ten seconds
    alarm_time = time;
    alarm_time.sec += 5;

    // Initialize RTC, set time and data, register interrupt handler callback function and enable seconds interrupt
    rtc_init(&cfg);

    // Start RTC
    rtc_set_time_clndr(&time, NULL);
    rtc_set_alarm(&alarm_time, NULL, RTC_ALARM_EN_SEC);

    // Clear pending interrupts
    rtc_get_event_flags();
    rtc_register_intr(rtc_interrupt_hdlr, RTC_INTR_ALRM);

    }

    static void rtc_interrupt_hdlr(uint8_t event)
    {

    app_resume_system_from_sleep();
    app_easy_timer(1, user_app_adv_restart);

    }

    static void app_resume_system_from_sleep(void)
    {

    if (arch_ble_ext_wakeup_get())
    {
    arch_set_sleep_mode(app_default_sleep_mode);
    arch_ble_force_wakeup();
    arch_ble_ext_wakeup_off();
    app_easy_wakeup();
    }

    }

  • Hi Yoshihiko,

    Thank you for the reply.
    Please refer on the arch_set_deep_sleep API:

    /**
     ****************************************************************************************
     * @brief       Activates deep sleep mode.
     * @param[in]   ram1           Selects the RAM1 state (on/off) during the hibernation.
     * @param[in]   ram2           Selects the RAM2 state (on/off) during the hibernation.
     * @param[in]   ram3           Selects the RAM3 state (on/off) during the hibernation.
     * @param[in]   pad_latch_en   true = Enable latching of pads state during sleep,
     *                             false = Disable latching of pads state during sleep.
     * @details     The system can wake-up from the following sources:
     *                  - POR (power on reset)
     *                  - GPIO(s) using the wake-up controller
     *                  - Interrupt generated by the RTC
     *                  - Interrupt generated by the Timer1
     *
     * @note        The wake-up condition must be configured prior to putting the system in
     *              deep sleep.
     *              If RTC and Timer1 are not going to be used as wake-up sources, it is
     *              recommended to close the PD_TIM prior to putting the system in deep sleep.
     *              The exit from the deep sleep state causes a system reboot.
     ****************************************************************************************
     */
    void arch_set_deep_sleep(pd_sys_down_ram_t ram1,
                             pd_sys_down_ram_t ram2,
                             pd_sys_down_ram_t ram3,
                             bool pad_latch_en);

    Please try to call the API while the pad_latch_en parameter is set to true to keep the state of the GPIOs and there is no reason to re-configure the Peripheral blocks. 

    Best Regards,
    OV_Renesas

  • I fixed like this:

    arch_set_deep_sleep(PD_SYS_DOWN_RAM_ON, PD_SYS_DOWN_RAM_ON, PD_SYS_DOWN_RAM_ON, true);

     

    The GPIOs state is kept.

    But user_app_adv_restart was not performed after sleep.

    How can I fix?

  • Hi Yoshihiko,

    after wake up, the BLE will start adv, you do not need to restart the adv.

    Please try the default example of the RTC wake up, if you want the pin latched just need to set the pad_latch_en to true is ok.

    BR,

    JH_Renesas