• AVR Freaks

Hot!ASF 3.45.0 / SAMR34 / Standby Sleep with Interupt

Author
mrpackethead
packet mangler
  • Total Posts : 967
  • Reward points : 0
  • Joined: 2007/04/01 23:33:39
  • Location: 0
  • Status: offline
2019/04/20 14:36:36 (permalink)
0

ASF 3.45.0 / SAMR34 / Standby Sleep with Interupt

Hi, i'm using a Microchip ATSAMR34, with ASF 3.45.0.   The R34 is a L21 ( mostly)  + Radio Modem combined.    
this is my first project with this chip architecture so its been quite a learning process.    I've got unstuck with trying to bring the device out of sleep ( its in STANDBY ) mode, using the button which is attached to one of the GPIOs.   
The device enters a loop where it should send a data packet on the radio,  then go into Standby for <interval> seconds, wake up, send another packet, go to sleep, etc etc.       My sleep function is below
ALong side this, i've set up button0 with an interupt. The idea is that if you push the button it should end the sleep immediately, and it will break out of the send/sleep/send/sleep loop.    
What actually happens  if you push the button while it is sleeping, is that it appears to remain asleep,  and stays asleep until the end of the specified interval, and then it processes's the interupt.   
The behaviour that i'd like is that it should immediately wake up, when you push the button. 
Any clues.  
 
void sleep(void)
{
//static bool deviceResetsForWakeup = false;
printf("\r\nSystem is going to sleep zzzzzzzz.....\r\n");
PMM_SleepReq_t sleepReq;
sleepReq.sleepTimeMs = CONF_DEFAULT_APP_SLEEP_TIME_MS;
sleepReq.pmmWakeupCallback = appWakeup;

//sleepReq.sleep_mode = CONF_PMM_SLEEPMODE_WHEN_IDLE; // this was orginal code, but is a define on a define.
sleepReq.sleep_mode = SLEEP_MODE_STANDBY; // this mode will consume about 1.4uA, but is not reset on wakeup
//sleepReq.sleep_mode = SLEEP_MODE_BACKUP; // this mode will consume about 740nA, and is reset on wakeup

if (CONF_PMM_SLEEPMODE_WHEN_IDLE == SLEEP_MODE_STANDBY)
 {
  deviceResetsForWakeup = false;
 }


if (true == LORAWAN_ReadyToSleep(deviceResetsForWakeup))
 {
 app_resources_uninit();
 if (PMM_SLEEP_REQ_DENIED == PMM_Sleep(&sleepReq))
 {
  HAL_Radio_resources_init();
  sio2host_init();
  appTaskState = RUN_STATE;
  appPostTask(DISPLAY_TASK_HANDLER);
  printf("\r\nsleep_not_ok, PMM_Sleep \r\n");
 }
}
else
{
 printf("\r\nsleep_not_ok\r\n");
 appTaskState = RUN_STATE;
 appPostTask(DISPLAY_TASK_HANDLER);
}
}


static void configure_eic_callback(void)
{
    extint_register_callback(extint_callback,
            BUTTON_0_EIC_LINE,
            EXTINT_CALLBACK_TYPE_DETECT);
}

/** Configures the External Interrupt Controller to detect changes in the board
 * button state.
 */
static void configure_extint(void)
{
    struct extint_chan_conf eint_chan_conf;
    extint_chan_get_config_defaults(&eint_chan_conf);

    eint_chan_conf.gpio_pin = BUTTON_0_EIC_PIN;
    eint_chan_conf.gpio_pin_mux = BUTTON_0_EIC_MUX;
    eint_chan_conf.detection_criteria = EXTINT_DETECT_FALLING;
    eint_chan_conf.filter_input_signal = true;
    eint_chan_conf.wake_if_sleeping = true;
    
    extint_chan_set_config(BUTTON_0_EIC_LINE, &eint_chan_conf);
}

static void extint_callback(void)
{
    PMM_Wakeup();
    extint_chan_disable_callback(BUTTON_0_EIC_LINE,EXTINT_CALLBACK_TYPE_DETECT); // disable the button interupt.
    
    button_interupt();
}

#1

1 Reply Related Threads

    mrpackethead
    packet mangler
    • Total Posts : 967
    • Reward points : 0
    • Joined: 2007/04/01 23:33:39
    • Location: 0
    • Status: offline
    Re: ASF 3.45.0 / SAMR34 / Standby Sleep with Interupt 2019/04/20 18:02:47 (permalink)
    0
    Grrh!

    Turns out i'd done something dumb and was not enabling the interupt before i put it to sleep.
    #2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5