6 years, 6 months ago.

how to disable SPI for power savings, nRF51822

Hi, I'm using nRF51822 along with a SPI sensor. I'm following this example on MBED.

https://os.mbed.com/users/jejuho/code/VTT_NODEV3_LIS3DH/

When I go to sleep via ble.waitForEvent(), I'm consuming about 300uA. This should be closer to 4uA. Without any of the SPI code, I get around 4uA. I googled how to enable/disable it, but I'm not sure is that's proper.

Is this correct?

NRF_SPI0->ENABLE = 0; disable

NRF_SPI0->ENABLE = 1; enable

#include "mbed.h"
#include "LIS3DH.h"
#include "ble/BLE.h"

#define MISO p4
#define CS p3
#define SCLK p7

static LIS3DH lis(MOSI, MISO, CS, SCLK);    
float x,y,z;
InterruptIn button1(p1);    //nRF51822 P0.0

AxesRaw_t accel_raw; 
bool flag_read_acc;

//ISR for I/O interrupt
void button1_int(void)
{
	//set flag on interrupt
    flag_read_acc=1;

int main ()
{
    //pc.baud(9600);
    //pc.printf("...started... \n\r");

    //Initialize SPI interface
    SPI spi(MOSI, MISO, SCLK); 
    spi.format(8,3);
    spi.frequency(8000000); 

    
    BLE &ble = BLE::Instance();
    ble.init();	//using this just for sleep
    

    //Initialize LIS3DH driver
    lis.InitLIS3DH(LIS3DH_NORMAL, LIS3DH_ODR_25Hz, LIS3DH_FULLSCALE_2);    //Init Acc-sensor
    //enable threshold to generate interrupt
    lis.SetLIS3DHActivityDetection(10, LIS3DH_INT_MODE_6D_MOVEMENT, 1);

    //set interrupt pin
    button1.mode(PullDown);
    button1.rise(button1_int);
    lis.LIS3DH_ResetInt1Latch();

	
while (1) {	
    if (flag_read_acc == 1)
    {
		//do stuff in this routine
		flag_read_acc=0;	//reset flag
    }//end if flag
    
    lis.LIS3DH_ResetInt1Latch();    //move this to when you really want to release
    NRF_SPI0->ENABLE = 0;			//disable SPI?

    ble.waitForEvent();
    NRF_SPI0->ENABLE = 1;			//re-enable SPI

    //Initialize LIS3DH driver
    lis.InitLIS3DH(LIS3DH_NORMAL, LIS3DH_ODR_25Hz, LIS3DH_FULLSCALE_2);    //Init Acc-sensor
    //enable threshold to generate interrupt
    lis.SetLIS3DHActivityDetection(10, LIS3DH_INT_MODE_6D_MOVEMENT, 1);
	
    }//end while
}//end main()

Hi Eric

Did you ever get this to work. I cant seem to get rid of the 400ua power consumption at sleep after I have used any SPI devices!?

posted by Ben S 21 Oct 2018

2 Answers

6 years, 2 months ago.

Hi Eric

Did you ever get this to work. I cant seem to get rid of the 400ua power consumption at sleep after I have used any SPI devices!?

6 years, 6 months ago.

Hello Eric,

Yes you are correct. I am not sure if you have seen this discussion post on the Nordic website when searching around, but it goes over the board’s low power modes in more detail:

https://devzone.nordicsemi.com/f/nordic-q-a/1657/how-to-minimize-current-consumption-for-ble-application-on-nrf51822/7350#7350

Here is also their reference manual which details the enable/disable:

http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf

Hope this answers your question!

-Karen, team Mbed

If this solved your question, please make sure to click the "Thanks" link below!

Bump again, I am seeing this issue, if i use SPI or I2C, sleep current jumps to 400ua.

NRF_SPI0->ENABLE = 0;

Does not resolve this issue!

posted by Ben S 10 Nov 2018