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

  • Hi,

    These two lines will enable the RTC interrupt.

    IEN1 = 0x20;

    EA = 1;

    These two lines is a bit more magic.

    PWRDWN = 0x07; // Clear power down

    PWRDWN = 0x00;

    The first line will put the chip in standby mode, while the second line will put the chip in low power mode. The reason for the first line is that the MCU will actually wakeup 1.5ms prior to the RTC interrupt, the reason for this is to startup the 16MHz crystal so it is running by the time the actual RTC interrupt occurs. A >1.5ms delay would have the same effect, but with higher power consumption. The reason the 16MHz crystal is started is to ensure the radio can be used when the RTC interrupt occurs.

    To disable the UART when not in use you can clear the REN0 bit in S0CON register.

    Best regards,

    Kenneth

  • 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);
    }
  • Hi,

    I understand your questions, but I think it will be difficult for you to start developing your project on a rather old 8-bit MCU which we are no longer actively updating the SDK or documentation, and have limited debugging.

    I would recommend you to check out the nRF5232 or nRF51822 instead. These two chips are being updated regularly with both new documentation and SDK.

    Best regards,

    Kenneth

  • Hi Kenneth, the requirements of our product are fairly simple: read value, transmit, sleep, low power (coin cell) and long range. the LE1 best suits that. if i could get your help in figuring out the sleep part, that would be great.

    thanks,

    Mahesh

  • Hi Mahesh,

    I understand, but the nRF51822 and nRF52832 have lower power. Most of your questions are basically 8051 generic questions, but to quickly answer them:

    1. Init GPIO's, and release latch (to apply GPIO settings).

    2. Yes, to use the external clock, you need to set the pin as input.

    3. Sure.

    4. Yes (release on 0, lock on 2).

    1. Yes.

    2. Yes.

    3. No.

    1. At least it's a good idea.

    2. In memory retention mode there will be a reset on wakeup, so this else is to control if it should wait for the RTC interrupt, or init the RTC (first time run). Likely it is a better idea to look at the register retention mode.

    3. Yes.

    4. Normal operation if 0.

    Best regards,

    Kenneth

Related