本帖最后由 ddllxxrr 于 2015-3-2 20:46 编辑
在Atmle Studio6.2主界面插入开发板。则可直接打开例程:
sleepmgr_example_sam_rtt
这里用了rtt即(Real time timer)实时实钟来定时,深度睡眠5秒然后再在实时时钟中断中再唤醒
活动3秒钟再睡眠。
配置实时时钟在这里:
rtt_init(RTT, 32768);
/* Enable RTT interrupt */
NVIC_DisableIRQ(RTT_IRQn);
NVIC_ClearPendingIRQ(RTT_IRQn);
NVIC_SetPriority(RTT_IRQn, 0);
NVIC_EnableIRQ(RTT_IRQn);
rtt_enable_interrupt(RTT, RTT_MR_ALMIEN);
设置实时时钟唤醒及选择睡眠模式:
/* Set wakeup source to rtt_alarm */
pmc_set_fast_startup_input(PMC_FSMR_RTTAL);
#if ((!SAMG51) && (!SAMG53) && (!SAMG54))
supc_set_wakeup_mode(SUPC, SUPC_WUMR_RTTEN_ENABLE);
#endif
/* Initialize the sleep manager, lock initial mode. */
sleepmgr_init();
sleepmgr_lock_mode(current_sleep_mode);
而主循环在这里:
rtt_write_alarm_time(RTT, rtt_read_timer_value(RTT) + SLEEP_TIME);
/*
* Turn the activity status LED off to inform the user that the
* device is in a sleep mode.
*/
ioport_set_pin_level(LED_ACTIVITY_STATUS_PIN, LED_STATUS_OFF);
/*
* Go to sleep in the deepest allowed sleep mode (i.e. no
* deeper than the currently locked sleep mode).
*/
sleepmgr_enter_sleep();
/*
* Turn the activity status LED on to inform the user that the
* device is active.
*/
ioport_set_pin_level(LED_ACTIVITY_STATUS_PIN, LED_STATUS_ON);
/* Unlock the current sleep mode. */
sleepmgr_unlock_mode(current_sleep_mode);
/* Add a 3s delay. */
delay_s(ACTIVE_TIME);
/* Lock the next sleep mode. */
++current_sleep_mode;
if ((current_sleep_mode >= SLEEPMGR_NR_OF_MODES)) {
current_sleep_mode = SLEEPMGR_ACTIVE;
}
sleepmgr_lock_mode(current_sleep_mode);
运行的结果是:
灯灭五秒亮三秒。
|