Page 1 of 1

advice on pybd deepsleep wake up on X1

Posted: Tue Sep 22, 2020 8:37 am
by irsla
Hi Everybody,

I've been trying for days now to have my SF6W wake up on X1 after a deepsleep.

First of all let me explain my configuration.

the board (firmware v1.13) is "externally" powered via it's VUSB Pin, and controls a MMA5284Q (accelerometer) via I2C.
The MMA5284Q is configured to raise a interrupt on a tap, this will lower the INT pin (from 3v3 to 0v).

I read that the X1 wakeup can only work if you raise the pin, therefore I've added a PNP transistor that will reverse the process.

checking with multimeter shows that it works.

if I try to go to lightsleep everything works fine. the board goes to sleep, and is successfully woke up on the tap.

if I try to go to deepsleep the board never wakes up, although I can see the interruption (multimeter) being raised from the MMA5284Q.

I guess I'm doing something wrong, but I can't figure what ;) I would be grateful if anyone can point me to the right solution

If you need more information, please ask.

here the test code:

Code: Select all

import time
from pyb import Pin, ExtInt, LED, Switch
import machine
import MMA8452Q


ledR = LED(1)
ledG = LED(2)

# turn of red led as it was turned on in
sw = Switch()

def stop():
    global STOP
    global sw

    print("in stop")
    STOP = True


def wokeUP(line):
    print("pin change", line)

def loop(i2c):
    global STOP

    Accel = MMA8452Q.MMA8452Q(i2c)

    # configure the accel to raise interrupt on Z tap
    Accel.setupTap(0x80, 0x80, 0x08, True)

    while STOP is False:
        print("sleeping in 3")
        #need to readTap to reset the interrupt
        print("tapState: " + str(Accel.readTap()))

#ext = ExtInt(Pin('X1'), ExtInt.IRQ_RISING, Pin.PULL_UP, wokeUP)
pinX1 = Pin("X1", Pin.IN, Pin.PULL_DOWN)
pinX1.irq(trigger=Pin.IRQ_RISING, handler=wokeUP)

i2c = machine.I2C('X')
s = i2c.scan()

if len(s) > 0:

Re: advice on pybd deepsleep wake up on X1

Posted: Tue Sep 22, 2020 2:19 pm
by irsla
Continuing testing and understanding all this.

The timeout value works fine.

Code: Select all

while STOP is False:
        print("sleeping in 3")
        #need to readTap to reset the interrupt
        print("tapState: " + str(Accel.readTap()))
So my problem seams to be with the X1 signal.

Which by the way works in lightsleep

Re: advice on pybd deepsleep wake up on X1

Posted: Tue Sep 22, 2020 2:37 pm
by jimmo
I don't have a pybd in front of me right now to test, but I think the answer lies somewhere in one of these links:

viewtopic.php?f=20&t=8518&p=48337 -->

In short - it looks like you have to manually enable X1 (PA0) as a wakeup source. I'm not entirely sure why machine.deepsleep() doesn't do this for you.

Re: advice on pybd deepsleep wake up on X1

Posted: Tue Sep 22, 2020 3:02 pm
by irsla
Hi Jimmo,

Thanks for pointing the links, unfortunately it doesn't work

this line:

Code: Select all

stm.mem32[stm.PWR + stm.PWR_CSR] |= 1 << 8 # enable WKUP pin on PA0
indeed should enable the wake up pin PA0 / X1 (PWR_CSR2_EWUP1 although it's on PWR_CSR2 and not PWR_CSR) but when entering in the deepsleep the firmware will clear this pin

Code: Select all

    #if defined(STM32F7)
    // disable wake-up flags
    // clear global wake-up flag
    #elif defined(STM32H7)
I found this when you posted your message.

I've rebuild the firmware with the modified code, and my first test seems good.
It seems I'm able to wakeup on X1 raising

BTW we could configure it to wake on X1 falling.

Will post more once I've confirmed all this.

Re: advice on pybd deepsleep wake up on X1

Posted: Wed Sep 23, 2020 9:39 am
by irsla
Hi Everybody,

News of the day: I got it working by adding a few parameter to the deepsleep function.

I would like to share this patch with the community by having added to the main source code. I will move this discussion to the appropriate channel.


Re: advice on pybd deepsleep wake up on X1

Posted: Thu Sep 24, 2020 7:15 am
by pythoncoder
I am currently working to fix the problems with the micropower repo and the Pyboard D. I did some work on this in June to get X18 working, but it needs completing.

Status of deepsleep wake up on X1?

Posted: Thu Dec 31, 2020 3:36 pm
by webbhm
I was wondering if there were any updates on pin interrupt for deepsleep wake up.
I am wrapping up the testing of a Pyboard-D (SF2W) for a water quality sensor, and I would like the option of putting a reed switch between the RST pin and GND (or some other wiring) to wake the system. Ideally I could then trap this via:
if machine.reset_cause() == machine.WDT_RESET on start-up.

I have tried jumpering between RST and GND, and it seems to wake up when unplugging the jumper, but the reset_cause always comes back as machine.DEEPSLEEP_RESET, which is the same as the RTC alarm. The pin may be working, but I cannot identify it via the software. I may be missing something on how this is intended to work.

This in not necessary functionality for my project, but it would be easier to offload the data via wifi, rather than having to disassemble the package and pull out the SD card which contains the data.

I really like the Pyboard-D and micropython. It is a nice system to work with and the power sipping is great. I have emulated over a year of sampling (26,000 events) running off of 3 AA batteries, and believe it could go on much longer.

A solution to wake up on X1

Posted: Fri Jan 01, 2021 1:18 pm
by pythoncoder
I have fixed this but for reasons that elude me my PR languishes with no reason given. It seems odd to lose a feature long available on the Pyboard 1.x. You can access the PR but you will need to build firmware. See this doc for details.