<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sleep current: disabling TWI, pull-ups?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10678/sleep-current-disabling-twi-pull-ups</link><description>I&amp;#39;m developing some simple wireless temperature sensors based on NRF51822s. In essence, they take a temperature measurement from a sensor over TWI, send it to a base-station using the micro_esb libraries, and then go into SYSTEM ON sleep for a period</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 11 Jan 2016 00:42:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10678/sleep-current-disabling-twi-pull-ups" /><item><title>RE: Sleep current: disabling TWI, pull-ups?</title><link>https://devzone.nordicsemi.com/thread/39856?ContentTypeID=1</link><pubDate>Mon, 11 Jan 2016 00:42:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69cdc591-078f-405c-b600-33a2140c2eee</guid><dc:creator>Gavin</dc:creator><description>&lt;p&gt;Many thanks Ole. I finally got the opportunity to sit down with the laptop and a scope and after few  things tracked it down to the two pins (SW_LED and SW_TEST) that I was leaving in a pulled-up state when going into SYSTEM ON. By setting to them to NRF_GPIO_PIN_NOPULL before going into sleep, the current usage drops off to ~3uA.&lt;/p&gt;
&lt;p&gt;So the &amp;#39;main loop&amp;#39; section of the main routine is now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;	while (true)
{
    ackd=false;

			// Set switches as inputs pulled high
			nrf_gpio_cfg_input(SW_LED,NRF_GPIO_PIN_PULLUP);
			nrf_gpio_cfg_input(SW_TEST,NRF_GPIO_PIN_PULLUP);

		
		
			// -------------- SENSE ---------------------

			twi_master_init(); 		
			// Trigger a one-shot conversion from the temperature sensor
			write_buffer[0]=1; // i.e. Configuration register
			write_buffer[1]=129; // MSB 128=OS bit, 1=SD bit
			write_buffer[2]=0; // LSB 	
			if(twi_master_transfer(TMP102_ADDRESS , write_buffer, 3, TWI_ISSUE_STOP)){
			}			

			// Wait for OS bit to be re-set to 1 to signal end of conversion
			data_buffer[0]=0;
			while (data_buffer[0] &amp;amp;&amp;amp; 128!=128) {
				if (twi_master_transfer(TMP102_ADDRESS | TWI_READ_BIT, data_buffer, 2, TWI_ISSUE_STOP)) {
				}				
			}
			
			// Switch to temperature register (from config register)
			write_buffer[0]=0; // i.e. Temperature register
			write_buffer[1]=0; // MSB? 
			write_buffer[2]=0; // LSB? 	
			if(twi_master_transfer(TMP102_ADDRESS , write_buffer, 3, TWI_ISSUE_STOP)){
			}			
			
			// Read the temperature and place in the payload ready to send
			if (twi_master_transfer(TMP102_ADDRESS | TWI_READ_BIT, data_buffer, 2, TWI_ISSUE_STOP)) {
						tx_payload.data[2] = data_buffer[0];		
						tx_payload.data[3] = data_buffer[1];				
			}

			// Prepare data that will put TMP sensor into shutdown
			write_buffer[0]=1; // i.e. Configuration register
			write_buffer[1]=1; // MSB? 1=SHUTDOWN
			write_buffer[2]=0; // LSB? 

			if(twi_master_transfer(TMP102_ADDRESS , write_buffer, 3, TWI_ISSUE_STOP)){
			}
			
			// Disable TWI ready for sleep

			NRF_TWI1-&amp;gt;ENABLE= TWI_ENABLE_ENABLE_Disabled &amp;lt;&amp;lt; TWI_ENABLE_ENABLE_Pos;
			
			// -------------- TRANSMIT ---------------------
		
			if(uesb_write_tx_payload(&amp;amp;tx_payload) == UESB_SUCCESS)
			{
					tx_payload.data[0]++;
			}
		
			nrf_delay_ms(10);

			// set switches to NOPULL before going to sleep
			nrf_gpio_cfg_input(SW_LED, NRF_GPIO_PIN_NOPULL);
			nrf_gpio_cfg_input(SW_TEST, NRF_GPIO_PIN_NOPULL);

			
			// --------------- SLEEP ------------------------
			
			// define length of sleep according to position of SW_TEST switch

			NRF_RTC1-&amp;gt;PRESCALER = 0;
			NRF_RTC1-&amp;gt;EVTENSET = RTC_EVTEN_COMPARE0_Msk; 
			NRF_RTC1-&amp;gt;INTENSET = RTC_INTENSET_COMPARE0_Msk; 
			
			if (nrf_gpio_pin_read(SW_TEST)==0) {	
					NRF_RTC1-&amp;gt;CC[0] = 32768;				
			}
			else
			{		
					NRF_RTC1-&amp;gt;CC[0] = 32768*60*5;						
			}				

			NVIC_EnableIRQ(RTC1_IRQn);				

			
			// Debug option: set switch pins to float? NRF_GPIO_PIN_NOPULL
			
			
			// Start the RTC timer
			NRF_RTC1-&amp;gt;TASKS_START = 1;

			// shut down the high-frequency clock
			NRF_CLOCK-&amp;gt;TASKS_HFCLKSTOP = 1;
			
			awake=false;
			while(!awake)
			{
				// Enter System ON sleep mode
				__WFE();  
				// Make sure any pending events are cleared
				__SEV();
				__WFE();                
			}
				
			// Stop and clear the RTC timer
			NRF_RTC1-&amp;gt;TASKS_STOP = 1;
			NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;	

			// Restart the hi-frequency clock
			NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
			NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
			while(NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);	
			
			
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sleep current: disabling TWI, pull-ups?</title><link>https://devzone.nordicsemi.com/thread/39855?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2016 10:28:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dd7d29d-ea37-4d57-8698-0f524bf90ccb</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;On the other hand, then your current consumption would have been much higher. Are you using twi_hw_master.c or twi_sw_master.c? It may be best if you just included the whole project in the post as a zip.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sleep current: disabling TWI, pull-ups?</title><link>https://devzone.nordicsemi.com/thread/39854?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2016 10:23:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2fedfbc-d2b5-477f-a533-ae9bf32fcc4d</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;I tested your code with the micro-esb example (replaced the main code) on nRF51 DK, and got about 3uA. This was of course without any twi slave attached and nothing to receive the packets over the air. I was using Keil. Which compiler are you using? You should make the variable &amp;quot;awake&amp;quot; volatile: &lt;code&gt;volatile bool awake&lt;/code&gt;, as some compilers will not &amp;quot;see&amp;quot; that this will ever be changed since it is set to true in interrupt context and therefore skip the sleep functions in &lt;code&gt;while(!awake){...}&lt;/code&gt;. Keil is forgiving when it comes to this, GCC is not.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sleep current: disabling TWI, pull-ups?</title><link>https://devzone.nordicsemi.com/thread/39853?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2016 14:58:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32b2732d-1628-40da-8bd0-38ea1450df3a</guid><dc:creator>Gavin</dc:creator><description>&lt;p&gt;Thanks for taking a look Ole. The code that I pasted into the original post above was just a snippet - I was starting the LFCLK outside of this loop, so I also included he commands to start it within the loop, just before the command to start the RTC1 timer. Unfortunately I still measure current draw of ~240uA.&lt;/p&gt;
&lt;p&gt;I am now wondering whether there is something else that I am doing, outside of this loop, which is causing the problem, so have pasted the whole of my main.c below. Very grateful if you had the time to take a look - I&amp;#39;m getting close to giving up :/&lt;/p&gt;
&lt;p&gt;(Apologies for weird formatting of the code - the website doesn&amp;#39;t seem to like &amp;lt;&amp;gt;s- happy to email you a raw copy if that would help)&lt;/p&gt;
&lt;p&gt;Gavin&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;////////////////////// Includes and defines ///////////////////

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;micro_esb.h&amp;quot;
#include &amp;quot;uesb_error_codes.h&amp;quot;
#include &amp;quot;nrf51.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;twi_master.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;

#define TMP102_ADDRESS 0x90 

#define LED_RED        5
#define LED_AMB        4
#define LED_GRN        3
#define SW_LED		2
#define SW_TEST   1



/////////////////////////// Globals ///////////////////////////

static uesb_payload_t tx_payload, rx_payload;
bool ackd;
bool awake;

/////////////////////////// Support routines /////////////////////

void uesb_event_handler()
{
    static uint32_t rf_interrupts;
    static uint32_t tx_attempts;
    
    uesb_get_clear_interrupts(&amp;amp;rf_interrupts);
    
    if(rf_interrupts &amp;amp; UESB_INT_TX_SUCCESS_MSK)
    {   
		ackd=true;
		// flash green LED if switch 2 set to ON
		if (nrf_gpio_pin_read(SW_LED)==0) {	
			nrf_gpio_pin_set(LED_GRN);
			nrf_delay_ms(25);
			nrf_gpio_pin_clear(LED_GRN);			
		}
	}
    
    if(rf_interrupts &amp;amp; UESB_INT_TX_FAILED_MSK)
    {
        uesb_flush_tx();
		// flash red LED if switch 2 set to ON
		if (nrf_gpio_pin_read(SW_LED)==0) {	
			nrf_gpio_pin_set(LED_RED);
			nrf_delay_ms(25);
			nrf_gpio_pin_clear(LED_RED);
		}
    }
    
    if(rf_interrupts &amp;amp; UESB_INT_RX_DR_MSK)
    {
        uesb_read_rx_payload(&amp;amp;rx_payload);
        NRF_GPIO-&amp;gt;OUTCLR = 0xFUL &amp;lt;&amp;lt; 8;
        NRF_GPIO-&amp;gt;OUTSET = (uint32_t)((rx_payload.data[2] &amp;amp; 0x0F) &amp;lt;&amp;lt; 8);
    }
    
    uesb_get_tx_attempts(&amp;amp;tx_attempts);
    NRF_GPIO-&amp;gt;OUTCLR = 0xFUL &amp;lt;&amp;lt; 12;
    NRF_GPIO-&amp;gt;OUTSET = (tx_attempts &amp;amp; 0x0F) &amp;lt;&amp;lt; 12;
}

void RTC1_IRQHandler(void)
{
// This handler will be run after wakeup from system ON (RTC wakeup)
	if(NRF_RTC1-&amp;gt;EVENTS_COMPARE[0])
	{
		NRF_RTC1-&amp;gt;EVENTS_COMPARE[0] = 0;
		awake=true;
		NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;
	}
}

/////////////////////////// Main  /////////////////////////////////

int main(void)
{
	
	// Declarations and initiations
	uint8_t write_buffer[3];
	uint8_t data_buffer[2];
	uint8_t power;
	power=0;
			
	// Set LED pins to high drive
	NRF_GPIO-&amp;gt;PIN_CNF[LED_RED] = (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos)
																| (GPIO_PIN_CNF_DRIVE_H0H1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos)
																| (GPIO_PIN_CNF_PULL_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos)
																| (GPIO_PIN_CNF_INPUT_Connect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos)
																| (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
	NRF_GPIO-&amp;gt;PIN_CNF[LED_AMB] = (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos)
																| (GPIO_PIN_CNF_DRIVE_H0H1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos)
																| (GPIO_PIN_CNF_PULL_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos)
																| (GPIO_PIN_CNF_INPUT_Connect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos)
																| (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
	NRF_GPIO-&amp;gt;PIN_CNF[LED_GRN] = (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos)
																| (GPIO_PIN_CNF_DRIVE_H0H1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos)
																| (GPIO_PIN_CNF_PULL_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos)
																| (GPIO_PIN_CNF_INPUT_Connect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos)
																| (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
	
	// Set switches as inputs pulled high
	nrf_gpio_cfg_input(SW_LED,NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_input(SW_TEST,NRF_GPIO_PIN_PULLUP);
	
	
	// Put power up high for testing purposes
	uesb_set_tx_power(UESB_TX_POWER_4DBM);

	// Set receive address
	uint8_t rx_addr_p0[] = {0xD2, 0xF0, 0xF0, 0xF0, 0xF0};
	uint8_t rx_addr_p1[] = {0xE1, 0xF0, 0xF0, 0xF0, 0xF0};
	uint8_t rx_addr_p2   = 0x66;	

	// Start the high-frequency clock - we&amp;#39;ll need it for the radio
	NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
	NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
	while(NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);	

	// Configure the radio
	uesb_config_t uesb_config       = UESB_DEFAULT_CONFIG;
	uesb_config.rf_channel          = 5;
	uesb_config.crc                 = UESB_CRC_16BIT;
	uesb_config.retransmit_count    = 6;
	uesb_config.retransmit_delay    = 500;
	uesb_config.dynamic_ack_enabled = true;
	uesb_config.protocol            = UESB_PROTOCOL_ESB_DPL;
	uesb_config.bitrate             = UESB_BITRATE_1MBPS;
	uesb_config.event_handler       = uesb_event_handler;
	
	uesb_init(&amp;amp;uesb_config);
	uesb_set_address(UESB_ADDRESS_PIPE0, rx_addr_p0);
	uesb_set_address(UESB_ADDRESS_PIPE1, rx_addr_p1);
	uesb_set_address(UESB_ADDRESS_PIPE2, &amp;amp;rx_addr_p2);

	// Load the payload with some dummy information and chip ID
	tx_payload.length  = 13;
	tx_payload.pipe    = 0;
	tx_payload.data[0] = 0x01;
	tx_payload.data[1] = 0x02;
	tx_payload.data[2] = 0x03;
	tx_payload.data[3] = 0x04;

	tx_payload.data[4] = NRF_FICR-&amp;gt;DEVICEID[0] &amp;amp; 255;
	tx_payload.data[5] = (NRF_FICR-&amp;gt;DEVICEID[0] &amp;gt;&amp;gt; 8) &amp;amp;255;
	tx_payload.data[6] = (NRF_FICR-&amp;gt;DEVICEID[0] &amp;gt;&amp;gt; 16) &amp;amp;255;;
	tx_payload.data[7] = (NRF_FICR-&amp;gt;DEVICEID[0] &amp;gt;&amp;gt; 24) &amp;amp;255;;

	tx_payload.data[8] = NRF_FICR-&amp;gt;DEVICEID[1] &amp;amp; 255;
	tx_payload.data[9] = (NRF_FICR-&amp;gt;DEVICEID[1] &amp;gt;&amp;gt; 8) &amp;amp;255;
	tx_payload.data[10] = (NRF_FICR-&amp;gt;DEVICEID[1] &amp;gt;&amp;gt; 16) &amp;amp;255;;
	tx_payload.data[11] = (NRF_FICR-&amp;gt;DEVICEID[1] &amp;gt;&amp;gt; 24) &amp;amp;255;;
	
	tx_payload.data[12] = power;


	// Configure RTC clock for SYSTEM ON sleep
	
	// Use internal 32kHz RC
	NRF_CLOCK-&amp;gt;LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos;
	
	// Start the 32 kHz clock, and wait for the start up to complete
	NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
	NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;
	while(NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED == 0);
	
	// Configure the RTC to run at 5 second intervals, and make sure COMPARE0 generates an interrupt (this will be the wakeup source)
	NRF_RTC1-&amp;gt;PRESCALER = 0;
	NRF_RTC1-&amp;gt;EVTENSET = RTC_EVTEN_COMPARE0_Msk; 
	NRF_RTC1-&amp;gt;INTENSET = RTC_INTENSET_COMPARE0_Msk; 
	NRF_RTC1-&amp;gt;CC[0] = 32768;
	NVIC_EnableIRQ(RTC1_IRQn);
					
	// Configure the RAM retention parameters
	NRF_POWER-&amp;gt;RAMON = POWER_RAMON_ONRAM0_RAM0On   &amp;lt;&amp;lt; POWER_RAMON_ONRAM0_Pos
									 | POWER_RAMON_ONRAM1_RAM1Off  &amp;lt;&amp;lt; POWER_RAMON_ONRAM1_Pos
									 | POWER_RAMON_OFFRAM0_RAM0Off &amp;lt;&amp;lt; POWER_RAMON_OFFRAM0_Pos
									 | POWER_RAMON_OFFRAM1_RAM1Off &amp;lt;&amp;lt; POWER_RAMON_OFFRAM1_Pos;		 


	// Initialise I2C
	twi_master_init(); 

	// Prepare data that will put TMP sensor into shutdown
	write_buffer[0]=1; // i.e. Configuration register
	write_buffer[1]=1; // MSB? 1=SHUTDOWN
	write_buffer[2]=0; // LSB? 

	if(twi_master_transfer(TMP102_ADDRESS , write_buffer, 3, TWI_ISSUE_STOP)){
	}
	
	// Turn I2C peripheral off (it uses the high-frequency clock, which we will need to turn off later)
	NRF_TWI1-&amp;gt;ENABLE=0;
	NRF_TWI1-&amp;gt;ENABLE          = TWI_ENABLE_ENABLE_Disabled &amp;lt;&amp;lt; TWI_ENABLE_ENABLE_Pos;
	
	// Prepare data that will trigger a one-shot conversion from the tmp sensor
	write_buffer[0]=1; // i.e. Configuration register
	write_buffer[1]=128; // MSB? 128=OS bit
	write_buffer[2]=0; // LSB? 
	
	
///////////////////////// Main loop //////////////////////////////////

	while (true)
    {
        ackd=false;

				// -------------- SENSE ---------------------

				twi_master_init(); 		
				// Trigger a one-shot conversion from the temperature sensor
				write_buffer[0]=1; // i.e. Configuration register
				write_buffer[1]=129; // MSB 128=OS bit, 1=SD bit
				write_buffer[2]=0; // LSB 	
				if(twi_master_transfer(TMP102_ADDRESS , write_buffer, 3, TWI_ISSUE_STOP)){
				}			
	
				// Wait for OS bit to be re-set to 1 to signal end of conversion
				data_buffer[0]=0;
				while (data_buffer[0] &amp;amp;&amp;amp; 128!=128) {
					if (twi_master_transfer(TMP102_ADDRESS | TWI_READ_BIT, data_buffer, 2, TWI_ISSUE_STOP)) {
					}				
				}
				
				// Switch to temperature register (from config register)
				write_buffer[0]=0; // i.e. Temperature register
				write_buffer[1]=0; // MSB? 
				write_buffer[2]=0; // LSB? 	
				if(twi_master_transfer(TMP102_ADDRESS , write_buffer, 3, TWI_ISSUE_STOP)){
				}			
				
				// Read the temperature and place in the payload ready to send
				if (twi_master_transfer(TMP102_ADDRESS | TWI_READ_BIT, data_buffer, 2, TWI_ISSUE_STOP)) {
							tx_payload.data[2] = data_buffer[0];		
							tx_payload.data[3] = data_buffer[1];				
				}

				// Prepare data that will put TMP sensor into shutdown
				write_buffer[0]=1; // i.e. Configuration register
				write_buffer[1]=1; // MSB? 1=SHUTDOWN
				write_buffer[2]=0; // LSB? 

				if(twi_master_transfer(TMP102_ADDRESS , write_buffer, 3, TWI_ISSUE_STOP)){
				}
				
				// Disable TWI ready for sleep

				NRF_TWI1-&amp;gt;ENABLE= TWI_ENABLE_ENABLE_Disabled &amp;lt;&amp;lt; TWI_ENABLE_ENABLE_Pos;
				
				// -------------- TRANSMIT ---------------------
			
				if(uesb_write_tx_payload(&amp;amp;tx_payload) == UESB_SUCCESS)
				{
						tx_payload.data[0]++;
				}
			
				nrf_delay_ms(10);
				
							
				
				// --------------- SLEEP ------------------------
				
				// define length of sleep according to position of SW_TEST switch

				NRF_RTC1-&amp;gt;PRESCALER = 0;
				NRF_RTC1-&amp;gt;EVTENSET = RTC_EVTEN_COMPARE0_Msk; 
				NRF_RTC1-&amp;gt;INTENSET = RTC_INTENSET_COMPARE0_Msk; 
				
				if (nrf_gpio_pin_read(SW_TEST)==0) {	
						NRF_RTC1-&amp;gt;CC[0] = 32768;				
				}
				else
				{		
						NRF_RTC1-&amp;gt;CC[0] = 32768*60*5;						
				}				

				NVIC_EnableIRQ(RTC1_IRQn);				

				
				// Debug option: set switch pins to float? NRF_GPIO_PIN_NOPULL
				
				
				// Start the RTC timer
				NRF_RTC1-&amp;gt;TASKS_START = 1;

				// shut down the high-frequency clock
				NRF_CLOCK-&amp;gt;TASKS_HFCLKSTOP = 1;
				
				awake=false;
				while(!awake)
				{
					// Enter System ON sleep mode
					__WFE();  
					// Make sure any pending events are cleared
					__SEV();
					__WFE();                
				}
					
				// Stop and clear the RTC timer
				NRF_RTC1-&amp;gt;TASKS_STOP = 1;
				NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;	

				// Restart the hi-frequency clock
				NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
				NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
				while(NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);	
				
				
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sleep current: disabling TWI, pull-ups?</title><link>https://devzone.nordicsemi.com/thread/39852?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2015 13:17:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84807799-d9cc-4ecc-88e2-d7a9319ae2d5</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;Looks like the problem is with the RTC rather than the TWI. I tested it and found out that if the low frequency clock is not started when starting the RTC, it looks like the high frequency clock is forced on (from the current measurement). Anyhow, the RTC will not function if the low frequency clock is not started. Add this to your initialization code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;
while(NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED == 0);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>