[stm32f411] sleep mode and irq button

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
nesergen
Posts: 23
Joined: Mon Oct 26, 2020 9:17 pm

[stm32f411] sleep mode and irq button

Post by nesergen » Thu Jul 01, 2021 3:06 pm

Good day!
On my board I configured an irq interrupt button. I put the board into a light sleep mode. When a button is pressed during sleep, an interrupt and its associated function are triggered. And after activating waking up timer, another function is triggered. Here's my example:

Code: Select all

import machine, pyb

#пины с прерыванием 
tm0 = machine.Timer(mode=machine.Timer.PERIODIC, period = 100, callback = lambda x: pyb.LED(1).toggle())

def button_interrupt():
	print("Interruption...")
	tm0.deinit()
	tm0.init(mode=machine.Timer.PERIODIC, period = 1000, callback = lambda x: pyb.LED(1).toggle())

Button = pyb.Pin(pyb.Pin.board.PB4, pyb.Pin.IN, pyb.Pin.PULL_DOWN)# пин кнопка включения экрана
Button.irq( trigger=pyb.Pin.IRQ_RISING,  handler = lambda x: button_interrupt())


def wakeup_callback():
	tm0.deinit()
	tm0.init(mode=machine.Timer.PERIODIC, period = 5000, callback = lambda x: pyb.LED(1).toggle())


#--------start----------
print("Sleep interruption test...")
pyb.delay(5000) #delay for LED blink view

b_rtc = pyb.RTC()
b_rtc.wakeup(60000, lambda x: wakeup_callback() ) #плата засыпает (light_sleep) на X мин 
pyb.stop()
I'm wondering if it is possible to disable interrupts during sleep mode? I assumed that the board did not work during sleep and that it was necessary to set up wake-up in order to continue working. And here it turns out that the board is asleep, and some interruption works in the background and executes the commands assigned to it, it's strange. What is the meaning of such sleep?

Post Reply