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

Periodic current spikes while sleeping when twis is enabled

I need the nrf52 as a I2C slave, so I set up a very minimal example:

void i2c_event_handler(nrfx_twis_evt_t const *p_event)
{
    switch (p_event->type) {
    case NRFX_TWIS_EVT_READ_REQ:
        nrfx_twis_tx_prepare( ... );
        break;
    case NRFX_TWIS_EVT_READ_DONE:
        break;
    case NRFX_TWIS_EVT_READ_ERROR:
        break;
    case NRFX_TWIS_EVT_WRITE_REQ:
        nrfx_twis_rx_prepare( ... );
        break;
    case NRFX_TWIS_EVT_WRITE_DONE:
        break;
    case NRFX_TWIS_EVT_WRITE_ERROR:
        break;
    case NRFX_TWIS_EVT_GENERAL_ERROR:
        break;
    }
}

static void i2c_init(void)
{
    nrfx_twis_config_t config = {
        .addr = { 3, 0 },
        .scl  = PIN_I2C_SCL,
        .scl_pull = (nrf_gpio_pin_pull_t)NRFX_TWIS_DEFAULT_CONFIG_SCL_PULL,
        .sda = PIN_I2C_SDA,
        .sda_pull = (nrf_gpio_pin_pull_t)NRFX_TWIS_DEFAULT_CONFIG_SDA_PULL,
        .interrupt_priority = NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY,
    };
    nrfx_twis_init(&i2c_dev, &config, i2c_event_handler);
    nrfx_twis_enable(&i2c_dev);
}

void clock_event_handler(nrfx_clock_evt_type_t event) {}

static void clock_init(void)
{
    nrfx_err_t err_code;
    err_code = nrfx_clock_init(clock_event_handler);
    APP_ERROR_CHECK(err_code);
    nrfx_clock_enable();
    //nrfx_clock_lfclk_start();
}

static void power_management_init(void)
{
    ret_code_t err_code;
    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);
}

static void idle_state_handle(void)
{
    ret_code_t err_code;

    if (NRF_LOG_PROCESS() == false) {
        nrf_pwr_mgmt_run();
    }
}

int main(void)
{
    clock_init();
    power_management_init();
    i2c_init();

    for (;;) {
        idle_state_handle();
    }
}

which seems to work so far. the chip wakes up, receives the i2c msg and is able to send back data.

but if I look at the current consumption, I see a periodic peek (700Hz) and I have no idea by what it may be caused:

if I don't initialize the i2c, it looks like this:

any idea?

Parents Reply Children
Related