QUERY · ISSUE
uncaught exception in Timer(1) interrupt handler MemoryError:
proposed-close
Hello, here is my problem:
import pyb
import ps2
import encoder
from pyb import LED, Timer
from machine import I2C,Pin
from oled import SSD1306_I2C
def mainTimer_cb(cb):
'''
#函数功能:用于总体程序的逻辑定时功能
'''
global count
LED(3).toggle()
count += 1
print(count)
if (count%8) == 0:
LED(2).toggle()
elif (count%20) == 0:
count = 0
elif (count%5):
oled_draw(count)
def oled_draw(text):
oled.text(str(text),20,0)
count = 0
mainTimer = Timer(1, freq=2, callback=mainTimer_cb)
i2c = I2C(scl = Pin("X9"),sda = Pin("X10"),freq = 10000)
oled = SSD1306_I2C(128, 64, i2c) #创建oled对象
oled.text("count:",0,0)
oled.text("i love u!",20,40)
oled.show()
while True:
i = 0
when i ran this code in pyb, it always got the memory error. So i wanna ask how can i write my main code in callback function? Because i can do this by C in STM32, just so confused to the error.
CANDIDATE · ISSUE
Unable to catch MemoryError in ISR
I'm not sure if this is expected behavior, or a bug?
>>> def locked():
... try:
... _ = bytearray(1)
... print(False)
... return
... except MemoryError:
... pass
... print(True)
>>> locked()
False
>>> import micropython
>>>micropython.heap_lock();locked()
True
>>> from pyb import Timer
>>> tim = Timer(5)
>>> tim.init(freq=1, callback=locked)
>>> uncaught exception in Timer(5) interrupt handler
Traceback (most recent call last):
File "logger/logger.py", line 33, in heap_locked
MemoryError: