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

I2C AND attachInterrupt current consumption in sleep mode #291

Closed
dots123 opened this Issue Jul 2, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@dots123
Copy link

dots123 commented Jul 2, 2018

I'm using a module with NRF52832 (as a Generic NRF52 board with RC oscillator and s132) without any conections, excepting SWD interface. I put it into sleep mode with __WFI(); and it consumes 2.6 uA.
When I add an attachInterrupt the current jumps to ~12 uA, which is fine for me.

But when I initialise my accelerometer (using Sparkfun's MMA8452Q library, but in sleep mode (~8 uA)) the current jumps to 450 uA, which is not ok.

Now, if I remove attachInterrupt and keep only the accelerometer, it consume only 2.6 uA (like in the begining).

It's normal to consume 450 uA when are both?

@coltonottley

This comment has been minimized.

Copy link

coltonottley commented Jul 19, 2018

Hey Dots123,

I know nothing about the Sandeepmistry implementation of the gpiote driver but I know in the Nordic SDK if you enable the high accuracy mode on the pin change interrupt you'll see exactly the 450 uA power consumption you described. Setting hi_accuracy to false will fix it.

Colton

@dots123

This comment has been minimized.

Copy link
Author

dots123 commented Jul 23, 2018

Hi Colton,

Quite good observation, thank you!
I'll search for a possible adaptation!

@coltonottley

This comment has been minimized.

Copy link

coltonottley commented Jul 24, 2018

I looked into the sandeepmistry WInterrupts.c file for the attachInterrupt function and it does look like they only implemented the hi_accu version of the nRF52 pin interrupt. Also, with the NRF52 if you don't disable the TWI interface before sleeping you will get increased power consumption. I always disable the TWI when I'm not using it. You can probably use Wire.end() to achieve this.

@dots123

This comment has been minimized.

Copy link
Author

dots123 commented Jul 24, 2018

Colton,

Thanks a lot for guiding!

I've tried with Wire.endTransmission() but nothing important happened.
But your idea of disabling was good. I've searched for an adaptation and I've discovered this:
NRF_TWI1->ENABLE=TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
But this alone doesn't work because of a nrf52 error on chip. You can read about Errata 89

So I've added:

*(volatile uint32_t *)0x40004FFC = 0;
*(volatile uint32_t *)0x40004FFC;
*(volatile uint32_t *)0x40004FFC = 1;

and it worked great.

Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.