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

NRF24LE1 (please help with power save coding)

Hello

I am quite a beginner and have been trying to get it work for 2 weeks now.

I would like to merge these 2 example codes from nordic:

  1. Shockburst TX example
  2. Registry retention timers on

I got reg retention to work, but the transmissioon does not go through. Can anyone help me with the working code where these 2 codes are combined...

I paste both of them here below:

1) Shock burst TX example:

#include "nrf24le1.h" #include "hal_clk.h" #include "hal_rtc.h"

static bool volatile radio_busy;

void main(void) { uint8_t payload[3];

while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M) {

}

RFCKEN = 1U; RF = 1U; EA = 1U; hal_nrf_set_power_mode(HAL_NRF_PWR_UP);

for(;;) { payload[0] = ~P0; hal_nrf_write_tx_payload(payload, 3U); CE_PULSE(); radio_busy = true; while (radio_busy) { } } }

NRF_ISR() { uint8_t irq_flags;

irq_flags = hal_nrf_get_clear_irq_flags();

switch(irq_flags) { case (1 << (uint8_t)HAL_NRF_TX_DS): radio_busy = false; break; case (1 << (uint8_t)HAL_NRF_MAX_RT): hal_nrf_flush_tx(); radio_busy = false; break; default: break; } }

2) Registry retention timers on

void mcu_init(void) { P0CON = 0x70; // Disable digital input buffer, pin used for 32kHz. P0CON = 0x71; // Disable digital input buffer, pin used for 32kHz.

P0DIR = 0x03; // Two pins used for 32 kHz XO. P1DIR = 0x00; P2DIR = 0x00; P3DIR = 0x00;

P0 = 0x00; P1 = 0x00; P2 = 0x00; P3 = 0x00; }

void wakeup_tick() interrupt INTERRUPT_TICK { P02 = !P02; }

void main(void) { mcu_init();

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);

// Wait for the 32kHz to startup (change phase) while((CLKLFCTRL&0x80)==0x80); while((CLKLFCTRL&0x80)!=0x80);

IEN1 = 0x20; EA = 1;

while(1) { // Register retention mode PWRDWN = 0x04; // Standby mode (wait for interrupt) PWRDWN = 0x07; // Clear PWRDWN PWRDWN = 0x00; // Continue to run code P03 = !P03; }; }

  • Hi Arvo

    I haven't played much with the nRF24LE1 lately, but I had a go at modifying the ESB TX example to use RTC sleep.

    You will find the result attached: main.c

    Can you give that a try?

    I tested it briefly, and verified that it sent a packet every second as expected.

    Best regards
    Torbjørn

  • Hello

    Thank you very much for the reply!

    I did try your code, it kind of worked, but it was not fast enough. The delay after I pressed the button was around 1.5 seconds and about 20% of the clicks did not COMe through at all.

    The datasheet says that wake up time should be around 1ms...

    Just to clarify, my setup is following: I have a transmitter with buttons connected to pins: P0.03 and P0.04 and reciever has LEDs connected to the same pins.

    Do you know what might be the probleem, how to get rid of the delay ?

    Thanks in advance !

    Arvo

  • Have you enabled wakeup on those pins through the WUOPC0/WUOPC1 registers? Also, what package type do you have? The 48-pin package does not allow you to enable wakeup on pin on P0.3 and P0.4, but the 32 and 24-pin packages do.

    Wakeup on most pins is active high only. Are your buttons active high or active low?

Related