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