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

Why is current consumption unstable in k_cpu_idle() after GPIO interrupt?

Current consumption during  k_cpu_idle() after GPIO interrupt does not take the same value. Why does this happen? Any idea? Thank you for reading this post in advance.

<Environment>
- DK v0.8.5(SB43 cut)
- modem firmware v1.0.0
- nrf; v1.0.0
- current measurement tool: multimeter

I configure GPIO11 as interrupt pin. I connect it to GND and disconnect again and again by jumper wire. After I connect it back to GND, the DK sometimes continuously consumes 25 uA and in another time 150 uA. 

CONFIG_TRUSTED_EXECUTION_NONSECURE=y

CONFIG_GPIO=y
CONFIG_SERIAL=n
# CONFIG_SERIAL=n in spm program
CONFIG_LOG=n

CONFIG_AT_HOST_LIBRARY=n

CONFIG_REBOOT=y

#include <zephyr.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gpio.h>
#include <device.h>

#define GPIO_IN_INT GPIO_IN_PIN11_Pos

struct device *gpio_controller;
struct gpio_callback gpio_cb;
bool is_interrupted;

void gpio_test_interrupt(struct device *gpio, struct gpio_callback *cb, u32_t pins) {
    is_interrupted = true;
}

u8_t init_gpio_interrupt() {
    int8_t ret;
    
    ret = gpio_pin_configure(gpio_controller, GPIO_IN_INT, (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH));
    if (ret) {
        return -1;
    }
    
    gpio_init_callback(&gpio_cb, gpio_test_interrupt, BIT(GPIO_IN_INT));

    ret = gpio_add_callback(gpio_controller, &gpio_cb);
    if (ret){
        return -1;
    }

    ret =  gpio_pin_enable_callback(gpio_controller, GPIO_IN_INT);
    if (ret){
        return -1;
    }

    return 0;
}

void main(void)
{
    gpio_controller = device_get_binding("GPIO_0");
    if (!gpio_controller) {
        sys_reboot();
    }

    if (init_gpio_interrupt() != 0) {
        sys_reboot();
    }

    while (1) {
        k_cpu_idle();
    }            
}

Related