This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

sleep w memory rentention problem

hi,

i'm not able to have the nRF24LE1 go to sleep. I'm using the example at the link below, to which I've added code for UART and ADC usage. Is there a way to end the UART (the opposite of the hal_uart_init() function)?

I need the LE1 to wake up, take an analog reading, write it to the UART, then go to sleep for x seconds. I'd like it to sleep for 10 seconds but it seems 2 is the maximum I can get with this MUP.

code example:

www.nordicsemi.com/.../How-to-setup-memory-retention-timers-on-on-the-nRF24LE1

In the example, what do these lines do?

IEN1 = 0x20; EA = 1;

// Go to standby mode and wait for RTC interrupt

PWRDWN = 0x07; // Clear power down

PWRDWN = 0x00;

Thanks!

Mahesh

Parents
  • Hi, I'm not able to get the sample code working -- the entire file from your website is listed at the very end. What am I missing? i have some questions about the code:

    In the function mcu_init():
    ---------------------------
    1. what is it's purpose?
    2. there is a comment "XOSC32K input". Is there anything in THIS function that has to do with the clock?
    3. for the 32-pin nRF24LE1 package, can setting P2DIR, P3DIR, P2 and P3 be skipped?
    4. does OPMCON = 0x00 just keep the pin directions PxDIR in memory during sleep?
    the function wakeup_tick():
    ---------------------------
    1. is it an ISR? 
    2. is it executed only on wake up from the tick? 
    3. do interrupts need to be disabled before doing any work in this? 
    the function main():
    --------------------
    1. does mcu_init() need to be the first thing that's called?
    2. is the code within the else {...} executed ONLY ONCE, upon startup, i.e. wake up is not from tick?
    3. is the code within if(PWRDWN & 0x40) {...} executed during the 2nd and all subsequent invocations of main()?
    4. what happens when PWRDWN is set to 0x00? bits 2:0 are b000. table 60, page 113 of the prod spec v1.16 does not specify what this means. it reads "Set system to power down if different from 000."

    general question:

    ------------------

    should WUCON be used at all?

    SAMPLE CODE BELOW:

    ------------------------

    /*
    * An nRF24LE1 MEMORY RETENTION TIMER ON example application 
    */
    #include <Nordic\reg24le1.h>
    #include <stdint.h>
    #include "hal_clk.h"
    #include "hal_rtc.h"
    uint8_t xdata toggle;
    void mcu_init(void)
    {
    // XOSC32K input
    P0DIR = 0x03;
    P1DIR = 0x00;
    P2DIR = 0x00;
    P3DIR = 0x00;
    P0 = 0x00;
    P1 = 0x00;
    P2 = 0x00;
    P3 = 0x00;
    // Open latch 
    OPMCON = 0x00; 
    }
    void wakeup_tick() interrupt INTERRUPT_TICK
    {
    // Toggle output on wakeup
    P02 = toggle;
    toggle = !toggle;
    }
    void main(void)
    {
    mcu_init();
    // If wakeup from tick, turn on LED
    if(PWRDWN & 0x40)
    {
    IEN1 = 0x20;
    EA = 1; 
    // Go to standby mode and wait for RTC interrupt
    PWRDWN = 0x07;
    // Clear power down
    PWRDWN = 0x00;
    else
    {
    // Init RTC timer
    hal_rtc_start(false);
    hal_clklf_set_source(HAL_CLKLF_XOSC32K); 
    hal_rtc_set_compare_mode(HAL_RTC_COMPARE_MODE_0);
    hal_rtc_set_compare_value(0x7FFF);
    hal_rtc_start(true); 
    }
    // Lock latch
    OPMCON |= 0x02;
    // Memory retention mode timer on, system reset on wakeup
    PWRDWN = 0x03; 
    while(1);
    }
Reply
  • Hi, I'm not able to get the sample code working -- the entire file from your website is listed at the very end. What am I missing? i have some questions about the code:

    In the function mcu_init():
    ---------------------------
    1. what is it's purpose?
    2. there is a comment "XOSC32K input". Is there anything in THIS function that has to do with the clock?
    3. for the 32-pin nRF24LE1 package, can setting P2DIR, P3DIR, P2 and P3 be skipped?
    4. does OPMCON = 0x00 just keep the pin directions PxDIR in memory during sleep?
    the function wakeup_tick():
    ---------------------------
    1. is it an ISR? 
    2. is it executed only on wake up from the tick? 
    3. do interrupts need to be disabled before doing any work in this? 
    the function main():
    --------------------
    1. does mcu_init() need to be the first thing that's called?
    2. is the code within the else {...} executed ONLY ONCE, upon startup, i.e. wake up is not from tick?
    3. is the code within if(PWRDWN & 0x40) {...} executed during the 2nd and all subsequent invocations of main()?
    4. what happens when PWRDWN is set to 0x00? bits 2:0 are b000. table 60, page 113 of the prod spec v1.16 does not specify what this means. it reads "Set system to power down if different from 000."

    general question:

    ------------------

    should WUCON be used at all?

    SAMPLE CODE BELOW:

    ------------------------

    /*
    * An nRF24LE1 MEMORY RETENTION TIMER ON example application 
    */
    #include <Nordic\reg24le1.h>
    #include <stdint.h>
    #include "hal_clk.h"
    #include "hal_rtc.h"
    uint8_t xdata toggle;
    void mcu_init(void)
    {
    // XOSC32K input
    P0DIR = 0x03;
    P1DIR = 0x00;
    P2DIR = 0x00;
    P3DIR = 0x00;
    P0 = 0x00;
    P1 = 0x00;
    P2 = 0x00;
    P3 = 0x00;
    // Open latch 
    OPMCON = 0x00; 
    }
    void wakeup_tick() interrupt INTERRUPT_TICK
    {
    // Toggle output on wakeup
    P02 = toggle;
    toggle = !toggle;
    }
    void main(void)
    {
    mcu_init();
    // If wakeup from tick, turn on LED
    if(PWRDWN & 0x40)
    {
    IEN1 = 0x20;
    EA = 1; 
    // Go to standby mode and wait for RTC interrupt
    PWRDWN = 0x07;
    // Clear power down
    PWRDWN = 0x00;
    else
    {
    // Init RTC timer
    hal_rtc_start(false);
    hal_clklf_set_source(HAL_CLKLF_XOSC32K); 
    hal_rtc_set_compare_mode(HAL_RTC_COMPARE_MODE_0);
    hal_rtc_set_compare_value(0x7FFF);
    hal_rtc_start(true); 
    }
    // Lock latch
    OPMCON |= 0x02;
    // Memory retention mode timer on, system reset on wakeup
    PWRDWN = 0x03; 
    while(1);
    }
Children
No Data
Related