adafruit / adafruit/Adafruit_nRF52_Arduino

Extraordinary power consumption when using attachInterrupt and Wire (I2C)

Open
#742 5 comments 1 reaction 0 assignees View on GitHub
Bug
Dominant language
C
Stars
699
Forks
570
PR merge metrics
No merged PRs in 30d

Description

### Operating System

MacOS

### IDE version

1.8.8

### Board

Any board based on nrf52832

### BSP version

1.3.0

### Sketch

The code snippit below seems to be the simplest way to express the issue:
```c
#include
#include //I2C library

#define INT_PIN 15

volatile unsigned long ms = 25;

void irqHandler()
{
#if CFG_SYSVIEW
SEGGER_SYSVIEW_RecordEnterISR();
#endif

ms = 2000;

#if CFG_SYSVIEW
SEGGER_SYSVIEW_RecordExitISR();
#endif
}

void setup() {
Bluefruit.begin();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, !LED_STATE_ON);

Wire.begin();
delay(100);

Wire.beginTransmission(0x0E);
Wire.write(0x0F);
Wire.endTransmission();

Wire.end();
delay(100);

pinMode(INT_PIN, INPUT_PULLUP);
attachInterrupt(INT_PIN, irqHandler, FALLING);
}

void loop()
{
digitalWrite(LED_BUILTIN, LED_STATE_ON);
delay(ms);
digitalWrite(LED_BUILTIN, !LED_STATE_ON);
delay(10000);
}
```

### What happened ?

When using BOTH the Wire Library (I2C) and attachInterrupt, power consumption increases dramatically from <11uA to 472uA.

### How to reproduce ?

I seem to have a similar issue to that which @ericlangel _originally posted in https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/165#issuecomment-1015328540_

Testing with the nrf52832: When using BOTH the Wire Library (I2C) and ```attachInterrupt```, power consumption increases dramatically from <11uA to 472uA.

I ran 4 tests and measured the idle current during the ```delay(10000)``` in loop:

1. Baseline (No I2C, no attachInterrupt) - 2.525uA
2. attachInterrupt only - 10.25uA
3. I2C only - 2.525uA
4. Both I2C and attachInterrupt - 472uA (**I expect to see 10.25uA here**)

These tests can be reproduced by modifying the above posted source in the following ways:

Test 1 - (2.525uA):
```c
// Wire.beginTransmission(0x0E);
// Wire.write(0x0F);
// Wire.endTransmission();
...
// attachInterrupt(INT_PIN, irqHandler, FALLING);
```

Test 2 - (10.25uA):
```c
// Wire.beginTransmission(0x0E);
// Wire.write(0x0F);
// Wire.endTransmission();
...
attachInterrupt(INT_PIN, irqHandler, FALLING);
```

Test 3 - (2.525uA):
```c
Wire.beginTransmission(0x0E);
Wire.write(0x0F);
Wire.endTransmission();
...
// attachInterrupt(INT_PIN, irqHandler, FALLING);
```

Test 4 - (472uA):
```c
Wire.beginTransmission(0x0E);
Wire.write(0x0F);
Wire.endTransmission();
...
attachInterrupt(INT_PIN, irqHandler, FALLING);
```

### Debug Log

_No response_

### Screenshots

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the posted nRF52832 sketch and reproduce the four current measurements, focusing on the interaction between Wire.begin()/Wire.end() and attachInterrupt(). Compare the I2C-only, interrupt-only, and combined cases, then trace the relevant Wire and interrupt entry points in the repository. Done means the combined case no longer causes the reported 472uA idle draw and remains functionally correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.