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();
}
}
/**
*@}
**/