Hi everyone. Here is my code for 2 different timers that put uc to sleep and wake it up(supposedly)
Definitions:
APP_TIMER_DEF(app_timer_uc); APP_TIMER_DEF(app_timer_lcd);
Create Timers:
static void create_uc_timer()
{
ret_code_t err_code;
// Create timers
err_code = app_timer_create(&app_timer_uc,
APP_TIMER_MODE_REPEATED,
uc_wake_handler);
APP_ERROR_CHECK(err_code);
}
static void create_lcd_timer()
{
ret_code_t err_code;
// Create timers
err_code = app_timer_create(&app_timer_lcd,
APP_TIMER_MODE_SINGLE_SHOT,
lcd_wake_handler);
APP_ERROR_CHECK(err_code);
}
Handlers:
static void uc_wake_handler(void * p_context)
{
uint32_t err_code;
nrf_drv_gpiote_out_toggle(LED_1);
err_code = app_timer_start(app_timer_lcd, APP_TIMER_TICKS(2000), NULL);
APP_ERROR_CHECK(err_code);
sleep_Uc();
}
static void lcd_wake_handler(void * p_context)
{
nrf_drv_gpiote_out_toggle(LED_2);
}
Main() function calls:
create_uc_timer();
create_lcd_timer();
err_code = app_timer_start(app_timer_uc, APP_TIMER_TICKS(1000), NULL);
APP_ERROR_CHECK(err_code);
sleep_Uc() function:
static void sleep_Uc(){
__SEV();
__WFE();
__WFE();
}
the code works fine when there is no sleep_Uc(); function. But when it is used, LED_1 toggle from low to high and uC goes to sleep. But the timer for lcd doesn't wake the processor. Additionally, when app_timer IRQ priority higher then GPIOTE IRQ priority, GPIOTE interrupts doesnt wake the uC either.
At the moment, IRQ_Priority of app_timer is 3, IRQ_Priority of GPIOTE is 2. When an GPIOTE interrupt occurs, uC wakes and goes to sleep immediatelly due to queued interrupts of app_timer i guess. How can i make the system wake with app_timer interrupts ?