确定
如果需要该信息,我正在使用带有Mighty Optiboot引导程序的Atmel 1284P。
所以我可以让这些东西单独起作用,但是当我把它们组合在一起时,我得到一个非常奇怪的结果。
我正在尝试使用带有Arduino休眠功能的RTC DS3231,并使用来自RTC的中断唤醒。 (实时时钟),RTC的SQW引脚连接到我的微中断引脚。
当单独完成这些事情时,每个事情都可以正常运行,但一旦将代码组合在一起冻结并且不会继续。
这是我现在的代码。 我试图每分钟唤醒微观,全局变量T是等待时间的间隔。
#include <avr/sleep.h>
#include <avr/power.h>
#include <Wire.h>
#include "ds3231.h"
struct ts t; // The Time structure
int T = 1; // The sleeping time in minutes
void setup()
{
pinMode(2,INPUT); // my interuppt is on pin 2
Serial.begin(9600);
Wire.begin();
DS3231_init(DS3231_INTCN); // Start the RTC interface
}
void loop()
{
Serial.println("Running"); // something to see that the micro is wake for a bit and not frozen
delay(5000); // a delay in my main code I will be loggin data
set_next_alarm(); /// set the next RTC alarm
DS3231_clear_a2f(); // clear a2 alarm flag and let INT go into high ,,, disabling the interrupt
sleep_enable(); // get sleep ready
attachInterrupt(2,wakeUp, LOW); // set the interrupt things
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is power down for most power savings
cli();
sei();
sleep_cpu(); // Sleeps here
sleep_disable(); // Wakes up here
// I have ccopied this bit of the sleeping code from the arduino fourums
}
void wakeUp() // run when interrupt is called
{
detachInterrupt(2); // detach the interrupt
sleep_disable();
}
void set_next_alarm(void) // Set the next alarm here
{
unsigned char wakeup_min;
DS3231_get(&t); // get the current time
// calculate the minute when the next alarm will be triggered
wakeup_min = (t.min / T + 1) * T;
if (wakeup_min > 59) {
wakeup_min -= 60;
}
boolean flags[4] = { 0, 1, 1, 1 };
DS3231_set_a2(wakeup_min, 0, 0, flags); // set the alarm 2
// activate Alarm2
DS3231_set_creg(DS3231_INTCN | DS3231_A2IE);
}
但是当代码运行时,我得到一个冻结的程序,它会休眠并在RTC上触发警报。 我知道RTC正在触发,因为我在SQW引脚上放了一个LED,看到它变为低电平但是RTC保持引脚保持低电平而没有其他事情发生。
任何想法或帮助将不胜感激我已经在这里待了3周,但在这里没有线索。
答案 0 :(得分:0)
好 因此,今天我厌倦了一种不同的睡眠方式,只需使用看门狗定时器就可以唤醒我的微观,每次睡眠8秒钟,然后醒来并检查警报是否触发并重新进入睡眠或记录数据。
我知道这不是我所需要的,但如果不能完美省电,它的效果确实很好。
我发现在mighty1284P代码的引导加载程序的引脚映射中存在一个错误,它与我需要的一个引脚及其中断有关..至少这是我读的所以我放弃了那个尝试所以我可以继续我的项目,因为我不够好搞乱引导装载程序。
所以我现在要修复,直到找到另一种方式然后我会再次更新这篇文章。