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();




	}
}

/**
 *@}
 **/
Parents
  • I haven't tried your code but, looking at it seems like you need to change

    NRF_LPCOMP->INTENSET = LPCOMP_INTENSET_UP_Enabled;
    

    to

    NRF_LPCOMP->INTENSET   = (LPCOMP_INTENSET_UP_Enabled << LPCOMP_INTENSET_UP_Pos);
    
  • 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.

Reply
  • 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.

Children
No Data
Related