Problem Waking Up MCU from interrupt after disabling TWIM

I have a nrf52832 custom board that I program using sandeepmistry Arduino core. Nothing to do here, I know it's Arduino but everything still works under the Nordic basis in the end..

I have an ADXL345 (accelerometer) connected to the TWIM (I2c) bus directly. The ADXL345 is generating an interruption everytime I double tap and I can see it on the scope. 

I have three scenarios here:

1) SCENARIO 1

 1.1) I send the MCU to sleep using __WFI();

 1.2) I don't disable the TWIM bus.

 1.3) When I double tap I see the interrupt signal RISING and the MCU wakes up, handles the interruption properly and goes to sleep back again.

 1.4) Power consumption in sleep: 0.66mA (TOO MUCH!)

2)  SCENARIO 2

  2.1) I send the MCU to sleep using __WFI();

  2.2) I disable the TWIM bus using following commands:

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

  2.3) When I double tap I see the interrupt signal RISING. The MCU wakes up but somewhere in the code I don't know. Is being waked up because I see more current consumption but the interrupt signal remains HIGH because the MCU is not handling the flag properly as it is not executing the RSI it should be executing once awake..

  2.4) Power consumption in sleep: 0.02mA (SO GOOD)

3) SCENARIO 3

  2.1) I send the MCU to "sleep" using __WFE();

  2.2) Disable TWIM bus using same commands as SCENARIO 2.

  2.3) When I double tap I see the interrupt signal RISING and MCU wakes up correctly. Everything is fine.

  2.4) Power consumption: 7mA (SUPER BAD).

Looks like __WFE() in combination with disabling i2c is working but is not having that sleep effect I want.

The idea is to have SCENARIO 2 working but I don't know where is the RSI going to... I tried reattaching the interrupt after these instructions are called before sleep but there's no effect.

Any help would be appreciated.

Thanks,

Toni Alomar

  • Hi Toni,

    Thank you contacting DevZone at NordicSemi.

    You have presented 3 different scenarios. I wanted to understand your issue and the measuring setup a bit more and at the same time would like to provide some information that might be useful.

    1) If you want to achieve lower power by disabling a device, you must first stop it. The STOP task may not always be needed (the peripheral might already be stopped), but if it is sent, we should wait till STOPPED event is received before disabling the device through the ENABLE register.

    2) Can you elaborate about your power consumption numbers. Specifically:
    (a) How / What setup you are using to measure. These numbers are peak or averages?
    (b) These numbers represent power consumption of whole SoC or your custom board?
    TWIM interface (nRF52832) has 50uA run current in active mode (0.05mA).

    3) It depends on your chip version as well, but nRF52832 Revision 3 Errata has this information that "Static current consumption of 0.4mA-0.5mA happens when using TWIM with GPIOTE". I can see that you have incorporated the workaround mentioned there.

    4) In your first case, MCU is in sleep state, but TWIM is enabled. Do you have other peripherals running / active / enabled?

    5) In the second case, MCU is in sleep state, but TWIM has been disabled. I would like to see your minimal working code and dig into registers to see what's happening and when.

    6) In your third case, MCI is in wait state using WFE. WFI and WFE can be different in the deep-down implementation. It also makes sense from your power dissipation results as well. Nonetheless, WFE is more relevant for multicore situation. 

    7) If case#1 is putting MCU in sleep, and only TWIM is enabled, and you report 0.66mA. How much mA before putting MCU into sleep?

    Can you please elaborate "How you are measuring power", "Which SDK version you are using", and I would like to see your minimal working code to check on my DK and measure using PPK. You can attach your project as a zip file.

    Regards,
    Naeem

Related