nrf82540 Dongle - reducing consumption during sleep.

Hello.

I need some advice - I'm a beginner. I tested the transition to sleep mode via __WFI for the nrf52840 Dongle (VS code, SDK v3.3.0). I need some advice - I'm a beginner. For nrf52840 Dongle (VS code, SDK v3.3.0) I tested sleep mode via __WFI. Sleep mode works, but I had to disable interrupts from RTC1. I solve the wakeup with an interrupt from RTC0 - I attach an code. In sleep mode the consumption is about 1.6mA. Can you advise me what and how to turn off (setup) so that the consumption is as low as possible when SYSTEM ON. I'll need to go back after the circuit wakes up. Thank you. 

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

#define PORT0_NI DT_NODELABEL(gpio0)
#define PORT1_NI DT_NODELABEL(gpio1)
const struct  device *port0 = DEVICE_DT_GET(PORT0_NI);
const struct  device *port1 = DEVICE_DT_GET(PORT1_NI);

#define LED_G 6
#define Butt 6

bool F_Butt_Off;
uint16_t Count_Butt;

// static void TIMER1_IRQHandler(void)
// {
//         if(NRF_TIMER1->EVENTS_COMPARE[0] != 0)
//         {
//                 NRF_TIMER1->EVENTS_COMPARE[0]=0;  
//                 gpio_pin_toggle(port0,LED_G);
//                 printf("Ubehlo 5 sekund.\n");
//         }
      
// }

// static void Start_Timer1(void)
// {
//         NRF_TIMER1->TASKS_CLEAR = 1;
//         NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
//         NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled;       // automaticky vynuluje TIMER4 po compare ???
        
//         NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_24Bit;
//         NRF_TIMER1->PRESCALER = 9;   // nie je možné použiť v Counter mode = 512
//         NRF_TIMER1->CC[0] = 156250;       // set value compare register 0 = 16MHz / 156250 / 512 = 5s = 0,2Hz
        
//         NRF_TIMER1->INTENSET = (TIMER_INTENCLR_COMPARE0_Enabled << TIMER_INTENCLR_COMPARE0_Pos);        // enable interrupt compare CC[0]

//         IRQ_DIRECT_CONNECT(TIMER1_IRQn, IRQ_PRIO_LOWEST, TIMER1_IRQHandler, 0);
//         irq_enable(TIMER1_IRQn);
//         NRF_TIMER1->TASKS_START=1;
// }


static void RTC0_IRQHandler(void)
{
        if(NRF_RTC0->EVENTS_COMPARE[1]!=0)
        {
                NRF_RTC0->EVENTS_COMPARE[1]=0;
                NRF_RTC0->TASKS_CLEAR=1;
                // gpio_pin_toggle(port0,LED_G);
                //gpio_pin_set(port0,LED_G,0);
                //printf("RTC0 IRQ 5 sec.\n");
                // uint32_t RTC0_Value;
                // RTC0_Value = NRF_RTC0->COUNTER;
                // printk("RTC0 = %d\n\r", RTC0_Value);
        }
}

static void Start_RTC0(void)
{
        NRF_RTC0->TASKS_STOP=1;
        NRF_RTC0->TASKS_CLEAR=1;
        NRF_RTC0->PRESCALER=0;
        
        NRF_RTC0->INTENSET=(RTC_INTENSET_COMPARE1_Enabled << RTC_INTENSET_COMPARE1_Pos);        
        // NRF_RTC0->INTENSET=( 1<<16);
        NRF_RTC0->EVTENSET=(RTC_EVTENSET_COMPARE1_Enabled << RTC_EVTENSET_COMPARE1_Pos);     
        //NRF_RTC0->EVTENSET=(1<<16);
        NRF_RTC0->CC[1]=163840;                //163840;
        IRQ_DIRECT_CONNECT(RTC0_IRQn, IRQ_PRIO_LOWEST, RTC0_IRQHandler,0);
        irq_enable(RTC0_IRQn);
        NRF_RTC0->TASKS_START=1;
}

int main(void)
{
        gpio_pin_configure(port0, LED_G, GPIO_OUTPUT);
        // Nastavenie pre Port1 - pin 6 = P1.06, Priamo register PIN_CFG
        NRF_P1->PIN_CNF[Butt] = 0b1100;

        gpio_pin_set(port0, LED_G, 0);

        // __disable_irq();
        irq_disable(RTC1_IRQn);
        
        Start_RTC0();

        // Start_Timer1();

        while(1)
        {
                if(gpio_pin_get(port1, Butt))
                {
                        F_Butt_Off=1;
                        Count_Butt=0;
                        //gpio_pin_set(port0, LED_G, 1);
                }
                else
                {
                        if(++Count_Butt>32000)
                        {
                                Count_Butt=32000;
                                //gpio_pin_set(port0, LED_G, 0);
                        }
                }

                if(Count_Butt==32000)
                {
                        if(F_Butt_Off)
                        {
                                F_Butt_Off=0;
                                // gpio_pin_toggle(port0,LED_G);
                                NRF_RTC0->TASKS_CLEAR=1;
                                gpio_pin_set(port0,LED_G, 1);

                                NRF_P1->PIN_CNF[Butt] = 0;

                                //printk("WFI activated.\n");
                                uint32_t RTC0_Value;
                                RTC0_Value = NRF_RTC0->COUNTER;
                                //printk("RTC0 = %d\n\r", RTC0_Value);
                                __WFI();
                                RTC0_Value = NRF_RTC0->COUNTER;
                                //printk("WakeUP - RTC0 = %d\n\r", RTC0_Value);
                                gpio_pin_set(port0,LED_G, 0);

                                NRF_P1->PIN_CNF[Butt] = 0b1100;
                        }
                }

                // if(NRF_RTC0->EVENTS_COMPARE[1]!=0)
                // {
                //         NRF_RTC0->EVENTS_COMPARE[1]=0;
                //         NRF_RTC0->TASKS_CLEAR=1;
                //         uint32_t RTC0_Value;
                //         RTC0_Value = NRF_RTC0->COUNTER;
                //         // k_msleep(100);
                //         printk("RTC0 = %d\n\r", RTC0_Value);

                //         gpio_pin_toggle(port0,LED_G);
                //         // k_msleep(100);
                //         printk("Ubehlo 5 sekund.\n");
                // }

        }

        return 0;
}

Parents
  • Hi Jaroslav, 
    I wouldn't suggest to use the nRF52840 dongle as your development platform. It's created as the backend tool for Nordic PC's application (for example nRF Sniffer) . 

    1.6mA when the CPU is sleeping is indeed high. 

    Could you let us know how did you do the measurement ? Do you have a power profiller ? 

    My suggestion is to get hold of a nRF52840 DK or nRF54L15 DK (nRF54 series is our latest chip and is recommended over the nRF52) and do the development on the DK instead. 

    You can test with some simple application that only put the CPU to sleep (and wake up with RTC to blink an LED for example) to see how low your current consumption is when CPU is put to sleep before you test with GPIO input. 

  • Hello. Thanks for the answer. I tried using an empty program using only __WFI - the consumption is the same 1.6mA - measured only with a multimeter (same result on two). I was hoping that if someone had experience how to achieve the lowest consumption on this module and what needs to be set for this. I have a few of these modules and I wanted to use them.

Reply
  • Hello. Thanks for the answer. I tried using an empty program using only __WFI - the consumption is the same 1.6mA - measured only with a multimeter (same result on two). I was hoping that if someone had experience how to achieve the lowest consumption on this module and what needs to be set for this. I have a few of these modules and I wanted to use them.

Children
Related