sleepmgr_sleep - waking up -SAMD21

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the below code, I put the SAMD21 to sleep before the main while loop. When an external interrupt is detected, the SAMD21 will wake up, print to the console and never hit the main loop. However, on the second time a external interrupt is detected, the device wakes up, prints the message and enters my main loop.

 

My question is; after the 1st interrupt is detected, shouldnt I hit the main loop?

#include <asf.h>
#include "conf_usart.h"
#include "interrupts_config.h"

void extint_detection_callback_pb23(void); // call back function for pb23 interrupt
#define CONFIG_SLEEPMGR_ENABLE

int main (void)
{
	system_init();
	configure_console(115200); // configure usart to 115200

	// configure pin pb23 with a pull-up resistor, asynchronous edge detection
	interrupt_conf_t config = {
		.gpio_pin =  PIN_PB23A_EIC_EXTINT7,
		.gpio_pin_mux = MUX_PB23A_EIC_EXTINT7,
		.gpio_pin_pull = EXTINT_PULL_UP,
		.detection_criteria = EXTINT_DETECT_HIGH,
		.eic_line = 7 // from the data sheet EXTINT[7]
	};
	
	configure_extint_channel(&config); // pass the pointer to our struct to the config function
	configure_extint_callbacks(7, extint_detection_callback_pb23);// call back for pb23	

	printf("SAMD21 Sleep with Interrupts\n\r");

	sleepmgr_sleep(SLEEPMGR_STANDBY);
	sleepmgr_enter_sleep();

	while (1) {

		printf("I am awake\n\r");

	}
}
void extint_detection_callback_pb23(void){

	uint8_t state = port_pin_get_input_level(PIN_PB23); // interrupt detected, get the pin state

	printf("Interrupt Detected\n");
	
	port_pin_set_output_level(LED_0_PIN, !state); // pull down resistor on the xplained pro board - set the LED high

}

 

This topic has a solution.

"When all else fails, read the directions"

Last Edited: Sun. May 7, 2017 - 12:06 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PhillyNJ wrote:

sleepmgr_sleep(SLEEPMGR_STANDBY); 
sleepmgr_enter_sleep();

 

Looks like I set 2 modes for the device to sleep. All I needed was:

 

sleepmgr_sleep(SLEEPMGR_STANDBY);

And the device sleeps and wakes up as expected...

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But for me its not working kindly let me know how to enter sleep mode.

I'm using SAMD21E16BU.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

npashine wrote:
But for me its not working kindly let me know how to enter sleep mode.

 

Make sure you have the ASF Sleep Manager module installed for the project and add:

 

sleepmgr_sleep(SLEEPMGR_STANDBY); // goto sleep

 

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its working now but can you tell me how to get the sleep in standby for below flow.

 

TC->for 10ms-->generates an event for the adc conversion.

ADC->converted and checked for the window value lower to wake up the cpu.

 

For for entire time of 10ms to event generation to adc conversion the cpu sleeps in standby..

only cpu gets waked up if the adc window value is lower.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

npashine wrote:
Its working now but can you tell me how to get the sleep in standby for below flow.

 

What have you tried? I would also suggest you open a new topic. Your question no longer relates to this topic. Make sure you post your question and the relevant code.

 

 

"When all else fails, read the directions"