Open mamama1 opened 2 years ago
Nice work mamama1. I found your comment interesting:
// Configure External Interrupt Controller (EIC) to GCLK2 which has been connected to OSCULP32K above, which in turn is ALWAYS running, even in deep sleep (can't be turned off) // It seems that this MUST happen AFTER the interrupt has been attached
I think the reason that you have to do this after the interrupt has been attached is
that attaching an interrupt calls the broken function configGCLK6()
which
corrupts the most recently configured clock. If you've just configured GCLK2
before attaching the interrupt, GCLK2
gets corrupted.
See issue #30.
I recommend patching my suggested fix in issue #30 if you're going to use this library.
I recommend forking this project. It's been like 3 years since your issue @denisbaylor and still it's not merged.
Deep sleep is one the THE MOST IMPORTANT aspect of MCU's since IoT is comming and comming fast, yet one of the less supported.
If any of you guys are willing to fork this library or make a sleep library from scratch for SAMD21 let me know, I would love to work with you guys!
@mamama1 I would love to see your entire code base. I have a small project going on where I could use your example.
seems like SAMD21 development is kind of dead. I haven't touched anything since 1,5 years ago and I can hardly remember anything. I'm sorry, but I think I've given away everything in my first post. I won't get better from there.
From your first post I don't know who is this
and who is regDir
. That is why I am asking. You've created an external class and just initiated it in setup?
Any idea why is SAMD21 dead?
After days of work (I am a noob), I have finally achieved the following:
The issues:
So, what I have done to achieve my goals (actually not too complex):
In Setup(), first thing to do for me was to attach OCSULP32K to GCLK2:
Then setup your pins according to your needs, I had some buttons connected:
Set the UART RX pins to INPUT_PULLUP as well
Attach my interrupt with an ISR on falling edge:
attachInterrupt(this->ButtonPin, myISR, FALLING);
Now comes the fat part, I wrote a sleep function which 1) saves all the pin configs 2) sets all pins which currently are INPUTs to INPUT_PULLUPs 3) sets MISO to INPUT_PULLUP (there might be more pins for which this should be done) and which puts the MCU to sleep and then after wakeup restores all the registers so the user program isn't affected by misconfigured GPIO pins.
Most probably, to reach library quality and broad compatibility with all the possible configurations and SAMD21 boards, this needs to be refined very much but as I said: I am a noob and this took me days to find out and to do.
I would be very happy to see the fixes refined and implemented into the LowPower library because in the current state, with floating pins, only level detection external interrupts and so on, in my humble opinion this is a little bit useless for real low power applications.
I mean, the SAMD21 is a way more powerful MCU than the AVR (328p for example) and still it can achieve way lower standby power consumption and I think that it is a pity that this potential is kind of wasted.
Thank you for your attention.