This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Wake up from power-off mode

I'm working in a project & I want to wake up the system from the sleep mode but it didn't wake up or I don't know what is expected on the wake up, will the system be run from the start of the main function or not.

I used a variable resistor to change the voltage to be compared with the reference value of the LPCOMP and to force this signal to be below the reference then to be above the reference but it didn't wake up, I tried the same example in another ble example but it failed also .

	#include <stdbool.h>
	#include "nrf.h"
	#include "app_error.h"
	#include "nrf_gpio.h"
	#include "nrf51_bitfields.h"
	#include "nrf_delay.h" 
	#include "boards.h"



static void gpio_config(void)
{
	nrf_gpio_cfg_input(26, NRF_GPIO_PIN_NOPULL);
		
	nrf_gpio_cfg_sense_input(26, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
	nrf_gpio_range_cfg_output(21, 24);
			nrf_delay_ms(500);
			nrf_gpio_pin_clear(LED_1);
			nrf_gpio_pin_clear(LED_2);
			nrf_gpio_pin_clear(LED_3);
			nrf_gpio_pin_clear(LED_4);
			nrf_delay_ms(500);
			nrf_gpio_pin_set(LED_1);
			nrf_gpio_pin_set(LED_2);
			nrf_gpio_pin_set(LED_3);
			nrf_gpio_pin_set(LED_4);
}


	


/** Configures and enables the LPCOMP
 */
void LPCOMP_init(void)
{	
		/* Enable interrupt on LPCOMP UP event */

	NRF_LPCOMP->INTENSET = LPCOMP_INTENSET_UP_Enabled;
	//NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;
	NVIC_EnableIRQ(LPCOMP_IRQn);	
	/* Configure LPCOMP - set input source to AVDD*4/8 */
	NRF_LPCOMP->REFSEL |= (LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling << LPCOMP_REFSEL_REFSEL_Pos);
	/* Configure LPCOMP - set reference input source to AIN pin 0, i.e. P0.26 */
	NRF_LPCOMP->PSEL |= (LPCOMP_PSEL_PSEL_AnalogInput0 << LPCOMP_PSEL_PSEL_Pos);
	NRF_LPCOMP->ANADETECT = LPCOMP_ANADETECT_ANADETECT_Up;
	/* Enable and start the low power comparator */
	NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled;	
	NRF_LPCOMP->TASKS_START = 1;
}



/* Interrupt handler for LPCOMP */
/*void LPCOMP_COMP_IRQHandler(void)
{
	// Clear event
	NRF_LPCOMP->EVENTS_CROSS = 0;
	
	// Sample the LPCOMP stores its state in the RESULT register. 
	// RESULT==0 means lower than reference voltage, 
	// RESULT==1 means higher than reference voltage
	NRF_LPCOMP->TASKS_SAMPLE = 1;
	//nrf_gpio_pin_write(RESULT_PIN, NRF_LPCOMP->RESULT);

	// Toggle pin to indicate triggering of event
	nrf_gpio_pin_toggle(EVENT_TRIGGERED_PIN);
}*/
static void power_manage(void)
	{
					NRF_POWER->SYSTEMOFF =POWER_SYSTEMOFF_SYSTEMOFF_Enter;
	}

/**
 * main function
 */
int main(void)
{
	gpio_config();
	LPCOMP_init();
	

	
	while (true)
	{	
		//Put CPU to sleep while waiting for interrupt to save power
	//	__WFI();

		power_manage();




	}
}

/**
 *@}
 **/
  • yes, but i cannot get it to work. Could be something related to hardware, i am not sure. system off mode is deep sleep mode and consumes least currect (leakage current) while sleep mode is not deep sleep where you can choose to keep selected modules on like RTC,RAM and HFCLK etc

  • and the sleep mode "not deep sleep" is developed with the WFE & sd_app_wait_evt(), also from where you knew that my code work ,what was the output after the wake up from the sleep mode

  • I did not understand your question, what do you mean by output? When the system wakes up from SystemOFF(Deep sleep) there is a reset first, but when the system wakes up from normal sleep (WFE/WFI) there is no reset, and it continues from where it sleeps. when it goes to sleep by WFE(sd_ble_wait_evt), any event or interrupt will wake the system up. If it is an interrupt then the interrupt is serviced first and then then execution returns to the for loop where power_manage is called. If you are asking about power consumption, i do not remember them but the devzone has covered that topic completely, you can browse for it :)

  • how did you test my code, I tested it by adding a voltage source to p0.026 and changing this voltage till it cross the threshold but found nothing changed after it !!!

  • which nersion of hardware are you using?, p0.26 is not connected to Anolog input of LPCOMP. I changed that part while testing your code. Please read the product specification to see where your Analog inputs are connected. I do bot have the code handy but I think VREF is connected to pin 0 and VAnalog 2 is connected to pin 1. Check the pin assignment for your product in the product specification document. I am sure P0.26 is not connected to LPCOMP in anyway. I also used external dynamic voltage output and change the voltage until it crooses the threshold defined in your code. It works fine if you connect the changing voltage to the correct pins.

Related