Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extraordinary power consumption when using attachInterrupt and Wire (I2C) #742

Open
jgartrel opened this issue Sep 13, 2022 · 3 comments
Open
Labels

Comments

@jgartrel
Copy link
Contributor

jgartrel commented Sep 13, 2022

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:

#include <bluefruit.h>
#include <Wire.h> //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 #165 (comment)

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

//  Wire.beginTransmission(0x0E);
//  Wire.write(0x0F);
//  Wire.endTransmission();
...
//  attachInterrupt(INT_PIN, irqHandler, FALLING);

Test 2 - (10.25uA):

//  Wire.beginTransmission(0x0E);
//  Wire.write(0x0F);
//  Wire.endTransmission();
...
  attachInterrupt(INT_PIN, irqHandler, FALLING);

Test 3 - (2.525uA):

  Wire.beginTransmission(0x0E);
  Wire.write(0x0F);
  Wire.endTransmission();
...
//  attachInterrupt(INT_PIN, irqHandler, FALLING);

Test 4 - (472uA):

  Wire.beginTransmission(0x0E);
  Wire.write(0x0F);
  Wire.endTransmission();
...
  attachInterrupt(INT_PIN, irqHandler, FALLING);

Debug Log

No response

Screenshots

No response

@jgartrel jgartrel added the Bug label Sep 13, 2022
@ericlangel
Copy link

any news here?

@jgartrel
Copy link
Contributor Author

I repeated the tests above on the Adafruit Feather nRF52 Bluefruit LE - nRF52832 board. I confirmed that this issue will appear on all boards based on the nRF52832 and likely affects all nRF52 boards using the v1.3.0 of this BSP.

All tests were done by using the nRF-PPK2 sourcing 3.7V connected to VBAT on the Feather nrf52832.

Results were as follows (using the same code and tests listed above):

Test 1 - (114uA average, 258uA peak):

//  Wire.beginTransmission(0x0E);
//  Wire.write(0x0F);
//  Wire.endTransmission();
...
//  attachInterrupt(INT_PIN, irqHandler, FALLING);

Test 2 - (119uA average, 247uA peak)

//  Wire.beginTransmission(0x0E);
//  Wire.write(0x0F);
//  Wire.endTransmission();
...
  attachInterrupt(INT_PIN, irqHandler, FALLING);
  • Test 3 - (123uA average, 262uA peak)
  Wire.beginTransmission(0x0E);
  Wire.write(0x0F);
  Wire.endTransmission();
...
//  attachInterrupt(INT_PIN, irqHandler, FALLING);
  • Test 4 - (643uA average, 3.95mA peak) - this is more than 515uA outside the expected range of 114uA - 128uA
  Wire.beginTransmission(0x0E);
  Wire.write(0x0F);
  Wire.endTransmission();
...
  attachInterrupt(INT_PIN, irqHandler, FALLING);

@jgartrel
Copy link
Contributor Author

jgartrel commented Jun 8, 2024

any news on this bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants