导航

    • 登录
    • 搜索
    • 版块
    • 产品
    • 教程
    • 论坛
    • 淘宝
    1. 主页
    2. 4gde
    4
    • 举报资料
    • 资料
    • 关注
    • 粉丝
    • 屏蔽
    • 帖子
    • 楼层
    • 最佳
    • 群组

    4gde

    @4gde

    0
    声望
    2
    楼层
    210
    资料浏览
    0
    粉丝
    0
    关注
    注册时间 最后登录

    4gde 关注

    4gde 发布的帖子

    • RE: 如何在定时器中断函数里面接收串口的数据

      了解了,谢谢大佬😄 😄

      发布在 OpenMV Cam
      4
      4gde
    • 如何在定时器中断函数里面接收串口的数据

      我尝试令stm32f1的板子和openmv通信
      下面是我的代码

      # Hello World Example
      #
      # Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
      
      import sensor, image, time, pyb, struct
      
      sensor.reset()                      # Reset and initialize the sensor.
      sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
      sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
      sensor.skip_frames(time = 2000)     # Wait for settings take effect.
      clock = time.clock()                # Create a clock object to track the FPS.
      
      
      ##初始化串口
      uart = pyb.UART(1, 115200, timeout_char=1000)                         # i使用给定波特率初始化
      uart.init(115200, bits=8, parity=None, stop=1, timeout_char=1000) # 使用给定参数初始化
      
      res=1
      
      def uart_call_back_(t):
          global uart
          if uart.any():
              res=uart.read()
              res = struct.unpack('B', res)
              res = hex(res)
              res = int(res)
              if res == 0xaf:
                  pyb.LED(1).toggle()
                  print('succes')
          return
      
      tim = pyb.Timer(4)              # create a timer object using timer 4  使用定时器4创建一个定时器对象
      tim.init(freq=1000)                # trigger at 2Hz 以2Hz触发
      tim.callback(uart_call_back_)
      
      def snshot():
          #clock.tick()                    # Update the FPS clock.
          img = sensor.snapshot()         # Take a picture and return the image.
          
          #print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                          # to the IDE. The FPS should increase once disconnected.
      
      while(True):
          snshot()
      
      

      我得到了这样的错误:
      uncaught exception in Timer(4) interrupt handler
      MemoryError:
      我尝试在while的主循环里面调用这个uart_call_back_这个函数而不是把它当成定时器的中断函数,可以运行,但是缺点就是,主循环里每一次循环都要拍照以及后续还要做图像的处理,这意味着可能不能及时的处理串口发来的信息。我想知道有什么方法可以解决这个error。

      发布在 OpenMV Cam
      4
      4gde