logo

调用外部中断时出现memory allocation failed, heap is locked?

2018-12-30 16:46
N
i56s

另麻烦看一下我的代码有什么问题吗?进入回调函数先屏蔽中断再开中断可以吗

from pyb import Pin, ExtInt
import sensor, image, time,pyb,micropython
micropython.alloc_emergency_exception_buf(100)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

def callback(line):
    ExtInt.disable()
    print("line =", line)
    ExtInt.enable()
extint = pyb.ExtInt(Pin('P0'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
while(True):
    clock.tick()
    img = sensor.snapshot()
2018-12-30 16:58
N
i56s

@kidswong999 因为之前可能没有消抖措施,所以出现RuntimeError: maximum recursion depth exceeded的错误,然后我在回调函数中加了屏蔽中断和开启中断的指令,再运行就出现上述的效果了。

2018-12-30 19:58
I
网红小智智 星瞳科技

回调函数里面不能使用外面程序里的对象(变量),比如你用的ExtInt。

在callback第一行里面加入`global ExtInt`

2018-12-30 20:15
N
i56s

这样还是不行呀

from pyb import Pin, ExtInt
import sensor, image, time,pyb,micropython
micropython.alloc_emergency_exception_buf(100)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

def callback(line):
    global ExtInt
    ExtInt.disable()
    print("line =", line)
    ExtInt.enable()
extint = pyb.ExtInt(Pin('P0'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
while(True):
    clock.tick()
    img = sensor.snapshot()