logo

定时器中断里面不能写串口通讯吗

2019-04-28 17:39
7
_13223518595

import time

from pyb import Pin, Timer

def tick(timer): # we will receive the timer object when being called

print("Timer callback")

if(uart.any()): print("6")

tim = Timer(4, freq=1) # create a timer object using timer 4 - trigger at 1Hz

tim.callback(tick) # set the callback to our tick function

while (True):

time.sleep(1000)

753a9a76-d1b9-4cf4-9d8f-374d577e7cd2.png
2019-04-28 17:46
7
_13223518595

如果不能用定时器中断的话 我不会只能用while实时监测串口接收到的字符吧?

2019-04-28 20:08
I
网红小智智 星瞳科技

是的,直接死循环判断uart.any()是最方便的。

I
网红小智智 星瞳科技

你的这个代码里,uart.any()会返回一个变量,但是中断函数里是没法分配内存的。