Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attaching an InterruptWakeup before and after deepSleep breaks RTCZero::getEpoch #58

Open
usbpc opened this issue Mar 16, 2023 · 2 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@usbpc
Copy link

usbpc commented Mar 16, 2023

I tested the following code on an MKR 1310:

#include <RTCZero.h>
#include <ArduinoLowPower.h>

void noop() {}

void setup() {
    Serial1.begin(115200);
    RTCZero rtc;
    rtc.begin();
    LowPower.attachInterruptWakeup(LORA_IRQ, noop, RISING);
    LowPower.deepSleep(1000);
    LowPower.attachInterruptWakeup(LORA_IRQ, noop, RISING);
    Serial1.println("This gets printed!");
    Serial1.println(rtc.getEpoch());
    Serial1.println("This never gets printed!");
}

void loop() {}

The first Serial1.println works and I get the message. But then reading the Epoch just results in an Endless Loop right here: https://github.com/arduino-libraries/RTCZero/blob/master/src/RTCZero.cpp#L488

So neither the Epoch nor the last Serial1.println get transmitted over Serial.

The code is just a minimal example of something that works around another problem where another library is overwriting the wakeup interrupt handler with a wrong one.

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Mar 17, 2023
@usbpc
Copy link
Author

usbpc commented Mar 17, 2023

I found a workaround, if I deep sleep before attatching the first Interrupt it works as I would expect.

@usbpc
Copy link
Author

usbpc commented Mar 27, 2023

The problem is not only with RTCZero, but also other parts of the system. I can get the Arduino stuck with this code aswell:

#include <LoRa.h>
#include <ArduinoLowPower.h>

void noop() {}

void setup() {
    Serial1.begin(115200);
    LowPower.deepSleep(1000);
    LowPower.attachInterruptWakeup(LORA_IRQ, noop, RISING);
    LowPower.deepSleep(1000);
    LoRa.begin(869587500);
    LowPower.attachInterruptWakeup(LORA_IRQ, noop, RISING);
    Serial1.println("This gets printed!");
    LoRa.receive();
    Serial1.println("This never gets printed!");
}

void loop() {}

This time it gets stuck in the LoRa.receive() call, some more investigation seems to indicate that in this case it is a problem with the SPI communication specifically it seems to loop indefinitely in this loop: https://github.com/arduino/ArduinoCore-samd/blob/a5d52dbf7bcf338de2042eb74cfba33993729c81/cores/arduino/SERCOM.cpp#L333

Any ideas on how I can debug this further to get the problem fixed quicker would be awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants