OpenMV与STM32之间的通讯(附源码)

打印 上一主题 下一主题

主题 890|帖子 890|积分 2670

本篇文章旨在记载我电赛期间使用openmv和stm32单片机之间举行串口通讯,将openmv辨认到的坐标传输给单片机。配景是基于2023年天下大门生电子筹划大赛E题:舵机云台追踪辨认。

单片机的串口通讯原理我便不再详细讲解,下面直接上代码分析。
值得注意的是接线:RX——>TX
                                 TX——>RX
                                 单片机和OPENMV必须共地
非常重要!!!!
一、串口通讯传输两个数据(x坐标和y坐标) 

(一)、 OPENMV串口通讯部分
  1. import sensor, image, time,math,pyb
  2. from pyb import UART,LED
  3. import json
  4. import ustruct
  5. sensor.reset()
  6. sensor.set_pixformat(sensor.RGB565)
  7. sensor.set_framesize(sensor.QVGA)
  8. sensor.skip_frames(time = 2000)
  9. sensor.set_auto_gain(False) # must be turned off for color tracking
  10. sensor.set_auto_whitebal(False) # must be turned off for color tracking
  11. red_threshold_01=(10, 100, 127, 32, -43, 67)
  12. clock = time.clock()
  13. uart = UART(3,115200)   #定义串口3变量
  14. uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
  15. def find_max(blobs):    #定义寻找色块面积最大的函数
  16.     max_size=0
  17.     for blob in blobs:
  18.         if blob.pixels() > max_size:
  19.             max_blob=blob
  20.             max_size = blob.pixels()
  21.     return max_blob
  22. def sending_data(cx,cy,cw,ch):
  23.     global uart;
  24.     #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
  25.     #data = bytearray(frame)
  26.     data = ustruct.pack("<bbhhhhb",      #格式为俩个字符俩个短整型(2字节)
  27.                    0x2C,                      #帧头1
  28.                    0x12,                      #帧头2
  29.                    int(cx), # up sample by 4   #数据1
  30.                    int(cy), # up sample by 4    #数据2
  31.                    int(cw), # up sample by 4    #数据1
  32.                    int(ch), # up sample by 4    #数据2
  33.                    0x5B)
  34.     uart.write(data);   #必须要传入一个字节数组
  35. while(True):
  36.     clock.tick()
  37.     img = sensor.snapshot()
  38.     blobs = img.find_blobs([red_threshold_01])
  39.     max_b = find_max(blobs)
  40.     cx=0;cy=0;
  41.     if blobs:
  42.             #如果找到了目标颜色
  43.             cx=max_b[5]
  44.             cy=max_b[6]
  45.             cw=max_b[2]
  46.             ch=max_b[3]
  47.             img.draw_rectangle(max_b[0:4]) # rect
  48.             img.draw_cross(max_b[5], max_b[6]) # cx, cy
  49.             FH = bytearray([0x2C,0x12,cx,cy,cw,ch,0x5B])
  50.             #sending_data(cx,cy,cw,ch)
  51.             uart.write(FH)
  52.             print(cx,cy,cw,ch)
复制代码
注意观察下图标注的部分,我不做详细讲解,但是很容易明确: 

接下来请看STM32串口通讯部分的代码:
  1. #include "uart.h"
  2. #include "oled.h"
  3. #include "stdio.h"
  4. static u8 Cx=0,Cy=0,Cw=0,Ch=0;
  5. void USART1_Init(void)
  6. {
  7.         //USART1_TX:PA 9   
  8.         //USART1_RX:PA10
  9.         GPIO_InitTypeDef GPIO_InitStructure;     //串口端口配置结构体变量
  10.         USART_InitTypeDef USART_InitStructure;   //串口参数配置结构体变量
  11.         NVIC_InitTypeDef NVIC_InitStructure;     //串口中断配置结构体变量
  12.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);       
  13.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);   //打开PA端口时钟
  14.     //USART1_TX   PA9
  15.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;                           //PA9
  16.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                   //设定IO口的输出速度为50MHz
  17.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                            //复用推挽输出
  18.     GPIO_Init(GPIOA, &GPIO_InitStructure);                               //初始化PA9
  19.     //USART1_RX          PA10
  20.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;             //PA10
  21.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  //浮空输入
  22.     GPIO_Init(GPIOA, &GPIO_InitStructure);                 //初始化PA10
  23.     //USART1 NVIC 配置
  24.     NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  25.                 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0 ;  //抢占优先级0
  26.                 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;                  //子优先级2
  27.                 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                          //IRQ通道使能
  28.                 NVIC_Init(&NVIC_InitStructure);                                  //根据指定的参数初始化VIC寄存器
  29.     //USART 初始化设置
  30.                 USART_InitStructure.USART_BaudRate = 115200;                  //串口波特率为115200
  31.                 USART_InitStructure.USART_WordLength = USART_WordLength_8b;   //字长为8位数据格式
  32.                 USART_InitStructure.USART_StopBits = USART_StopBits_1;        //一个停止位
  33.                 USART_InitStructure.USART_Parity = USART_Parity_No;           //无奇偶校验位
  34.                 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;   //无硬件数据流控制
  35.                 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;                          //收发模式
  36.     USART_Init(USART1, &USART_InitStructure);                     //初始化串口1
  37.     USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //使能中断
  38.     USART_Cmd(USART1, ENABLE);                     //使能串口1
  39.           //如下语句解决第1个字节无法正确发送出去的问题
  40.           USART_ClearFlag(USART1, USART_FLAG_TC);        //清串口1发送标志
  41.                
  42. }
  43. //USART1 全局中断服务函数
  44. void USART1_IRQHandler(void)                         
  45. {
  46.                 u8 com_data;
  47.                 u8 i;
  48.                 static u8 RxCounter1=0;
  49.                 static u16 RxBuffer1[10]={0};
  50.                 static u8 RxState = 0;       
  51.                 static u8 RxFlag1 = 0;
  52.                 if( USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)             //接收中断  
  53.                 {
  54.                                 USART_ClearITPendingBit(USART1,USART_IT_RXNE);   //清除中断标志
  55.                                 com_data = USART_ReceiveData(USART1);
  56.                        
  57.                                 if(RxState==0&&com_data==0x2C)  //0x2c帧头
  58.                                 {
  59.                                         RxState=1;
  60.                                         RxBuffer1[RxCounter1++]=com_data;OLED_Refresh();
  61.                                 }
  62.                
  63.                                 else if(RxState==1&&com_data==0x12)  //0x12帧头
  64.                                 {
  65.                                         RxState=2;
  66.                                         RxBuffer1[RxCounter1++]=com_data;
  67.                                 }
  68.                
  69.                                 else if(RxState==2)
  70.                                 {
  71.                                         RxBuffer1[RxCounter1++]=com_data;
  72.                                         if(RxCounter1>=10||com_data == 0x5B)       //RxBuffer1接受满了,接收数据结束
  73.                                         {
  74.                                                 RxState=3;
  75.                                                 RxFlag1=1;
  76.                                                 Cx=RxBuffer1[RxCounter1-5];
  77.                                                 Cy=RxBuffer1[RxCounter1-4];
  78.                                                 Cw=RxBuffer1[RxCounter1-3];
  79.                                                 Ch=RxBuffer1[RxCounter1-2];
  80.                                         }
  81.                                 }
  82.                
  83.                                 else if(RxState==3)                //检测是否接受到结束标志
  84.                                 {
  85.                                                 if(RxBuffer1[RxCounter1-1] == 0x5B)
  86.                                                 {
  87.                                                                         USART_ITConfig(USART1,USART_IT_RXNE,DISABLE);//关闭DTSABLE中断
  88.                                                                         if(RxFlag1)
  89.                                                                         {
  90.                                                                         OLED_Refresh();
  91.                                                                         OLED_ShowNum(0, 0,Cx,3,16,1);
  92.                                                                         OLED_ShowNum(0,17,Cy,3,16,1);
  93.                                                                         OLED_ShowNum(0,33,Cw,3,16,1);
  94.                                                                         OLED_ShowNum(0,49,Ch,3,16,1);
  95.                                                                         }
  96.                                                                         RxFlag1 = 0;
  97.                                                                         RxCounter1 = 0;
  98.                                                                         RxState = 0;
  99.                                                                         USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
  100.                                                 }
  101.                                                 else   //接收错误
  102.                                                 {
  103.                                                                         RxState = 0;
  104.                                                                         RxCounter1=0;
  105.                                                                         for(i=0;i<10;i++)
  106.                                                                         {
  107.                                                                                         RxBuffer1[i]=0x00;      //将存放数据数组清零
  108.                                                                         }
  109.                                                 }
  110.                                 }
  111.        
  112.                                 else   //接收异常
  113.                                 {
  114.                                                 RxState = 0;
  115.                                                 RxCounter1=0;
  116.                                                 for(i=0;i<10;i++)
  117.                                                 {
  118.                                                                 RxBuffer1[i]=0x00;      //将存放数据数组清零
  119.                                                 }
  120.                                 }
  121.                 }
  122.                
  123. }
复制代码
注意观察下面的图:

二、串口通讯传输多个数据(四个点的x、y坐标同时传输给STM32单片机)

(一)OPENMV串口部分
  1. from machine import Pin
  2. import sensor, image, time, pyb
  3. #import seekfree
  4. from pyb import UART
  5. # 初始化TFT180屏幕
  6. #lcd = seekfree.LCD180(3)
  7. # 初始化摄像头
  8. sensor.reset()
  9. sensor.set_pixformat(sensor.RGB565) # 设置图像色彩格式为RGB565格式
  10. sensor.set_framesize(sensor.QQVGA)  # 设置图像大小为160*120
  11. sensor.set_auto_whitebal(True)      # 设置自动白平衡
  12. sensor.set_brightness(3000)         # 设置亮度为3000
  13. sensor.skip_frames(time = 20)       # 跳过帧
  14. uart = UART(3, 115200,timeout_char=3000) #配置串口
  15. clock = time.clock()
  16. def sending_data(cx,cy,cw,ch):
  17.     global uart;
  18.     data = ustruct.pack("<bbhhb",      #格式为俩个字符俩个短整型(2字节)
  19.                    0x2C,                      #帧头1
  20.                    0x12,                      #帧头2
  21.                    int (cx1), # up sample by 4    #数据26
  22.                    int (cy1),
  23.                    int (cx2), # up sample by 4    #数据26
  24.                    int (cy2),
  25.                    int (cx3), # up sample by 4    #数据26
  26.                    int (cy3),
  27.                    int (cx4), # up sample by 4    #数据26
  28.                    int (cy4),
  29.                    0x5B)
  30.     uart.write(data);   #必须要传入一个字节数组
  31. while(True):
  32.     clock.tick()
  33.     img = sensor.snapshot()
  34. # -----矩形框部分-----
  35.     # 在图像中寻找矩形
  36.     for r in img.find_rects(threshold = 10000):
  37.         # 判断矩形边长是否符合要求
  38.         if r.w() > 20 and r.h() > 20:
  39.             # 在屏幕上框出矩形
  40.             img.draw_rectangle(r.rect(), color = (255, 0, 0), scale = 4)
  41.             # 获取矩形角点位置
  42.             corner = r.corners()
  43.             # 在屏幕上圈出矩形角点
  44.             img.draw_circle(corner[0][0], corner[0][1], 5, color = (0, 0, 255), thickness = 2, fill = False)
  45.             img.draw_circle(corner[1][0], corner[1][1], 5, color = (0, 0, 255), thickness = 2, fill = False)
  46.             img.draw_circle(corner[2][0], corner[2][1], 5, color = (0, 0, 255), thickness = 2, fill = False)
  47.             img.draw_circle(corner[3][0], corner[3][1], 5, color = (0, 0, 255), thickness = 2, fill = False)
  48.         # 打印四个角点坐标, 角点1的数组是corner[0], 坐标就是(corner[0][0],corner[0][1])
  49.         # 角点检测输出的角点排序每次不一定一致,矩形左上的角点有可能是corner0,1,2,3其中一个
  50.             corner1_str = f"corner1 = ({corner[0][0]},{corner[0][1]})"
  51.             corner2_str = f"corner2 = ({corner[1][0]},{corner[1][1]})"
  52.             corner3_str = f"corner3 = ({corner[2][0]},{corner[2][1]})"
  53.             corner4_str = f"corner4 = ({corner[3][0]},{corner[3][1]})"
  54.         print(corner1_str + "\n" + corner2_str + "\n" + corner3_str + "\n" + corner4_str)
  55.     # 显示到屏幕上,此部分会降低帧率
  56.     #lcd.show_image(img, 160, 120, 0, 0, zoom=0)  #屏幕显示
  57.     #串口通信传输的数据
  58.         cx1=(int)(corner[0][0]*10)
  59.         cy1=(int)(corner[0][1]*10)
  60.         cx2=(int)(corner[1][0]*10)
  61.         cy2=(int)(corner[1][1]*10)
  62.         cx3=(int)(corner[2][0]*10)
  63.         cy3=(int)(corner[2][1]*10)
  64.         cx4=(int)(corner[3][0]*10)
  65.         cy4=(int)(corner[3][1]*10)
  66.         FH=bytearray([0x2C,0x12,cx1,cy1,cx2,cy2,cx3,cy3,cx4,cy4,0x5B])
  67.         uart.write(FH)
  68.         cx1=0
  69.         cy1=0
  70.         cx2=0
  71.         cy2=0
  72.         cx3=0
  73.         cy3=0
  74.         cx4=0
  75.         cy4=0
  76.     # 打印帧率
  77.     print(clock.fps())
复制代码
下面请观察这幅代码截图:

(二)、STM32串口通讯部分
  1. #include "stm32f10x.h"                  // Device header
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include "OLED.h"
  5. #include "LED.h"
  6. #include "Serial.h"
  7. uint8_t Serial_RxData;
  8. uint8_t Serial_RxFlag;
  9. static int16_t Cx1=0,Cy1=0,Cx2=0,Cy2=0,Cx3=0,Cy3=0,Cx4=0,Cy4=0;
  10. int Cx5[16];//用于存放分段求的坐标值
  11. int Cy5[16];
  12. //static u8 RxFlag1 = 0;//串口中断接收标志位
  13. extern float Ang1,Ang2,AngFlag;
  14. extern float Angle1,Angle2;
  15. int avel_X1 ;
  16. int avel_X2 ;
  17. int avel_X3 ;
  18. int avel_X4 ;
  19. int avel_Y1 ;
  20. int avel_Y2 ;
  21. int avel_Y3 ;
  22. int avel_Y4 ;
  23. void Serial_Init(void)
  24. {
  25.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  26.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  27.        
  28.         //TX
  29.         GPIO_InitTypeDef GPIO_InitStructure;
  30.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  31.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  32.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  33.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  34.        
  35.         //RX
  36.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  37.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  38.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  39.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  40.        
  41.         USART_InitTypeDef USART_InitStructure;
  42.         USART_InitStructure.USART_BaudRate = 115200;
  43.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  44.         USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
  45.         USART_InitStructure.USART_Parity = USART_Parity_No;
  46.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  47.         USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  48.         USART_Init(USART3, &USART_InitStructure);
  49.        
  50.         USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
  51.        
  52.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  53.        
  54.         NVIC_InitTypeDef NVIC_InitStructure;
  55.         NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  56.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  57.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  58.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  59.         NVIC_Init(&NVIC_InitStructure);
  60.        
  61.         USART_Cmd(USART3, ENABLE);
  62. }
  63. void Serial_SendByte(uint8_t Byte)
  64. {
  65.         USART_SendData(USART3, Byte);
  66.         while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
  67. }
  68. void Serial_SendArray(uint8_t *Array, uint16_t Length)
  69. {
  70.         uint16_t i;
  71.         for (i = 0; i < Length; i ++)
  72.         {
  73.                 Serial_SendByte(Array[i]);
  74.         }
  75. }
  76. void Serial_SendString(char *String)
  77. {
  78.         uint8_t i;
  79.         for (i = 0; String[i] != '\0'; i ++)
  80.         {
  81.                 Serial_SendByte(String[i]);
  82.         }
  83. }
  84. uint32_t Serial_Pow(uint32_t X, uint32_t Y)
  85. {
  86.         uint32_t Result = 1;
  87.         while (Y --)
  88.         {
  89.                 Result *= X;
  90.         }
  91.         return Result;
  92. }
  93. void Serial_SendNumber(uint32_t Number, uint8_t Length)
  94. {
  95.         uint8_t i;
  96.         for (i = 0; i < Length; i ++)
  97.         {
  98.                 Serial_SendByte(Number / Serial_Pow(10, Length - i - 1) % 10 + '0');
  99.         }
  100. }
  101. int fputc(int ch, FILE *f)
  102. {
  103.         Serial_SendByte(ch);
  104.         return ch;
  105. }
  106. void Serial_Printf(char *format, ...)
  107. {
  108.         char String[100];
  109.         va_list arg;
  110.         va_start(arg, format);
  111.         vsprintf(String, format, arg);
  112.         va_end(arg);
  113.         Serial_SendString(String);
  114. }
  115. //USART3 全局中断服务函数
  116. void USART3_IRQHandler(void)                         
  117. {
  118.                 int com_data;
  119.                 u8 i;
  120.                 u8 Jieshou = 1;
  121.                
  122.                 static u8 RxCounter1=0;
  123.                 static int RxBuffer1[16]={0};
  124.                 static u8 RxState = 0;       
  125.                 static u8 RxFlag1 = 0;//串口中断接收标志位,已被移除至函数体外作为全局变量
  126.                 if( USART_GetITStatus(USART3,USART_IT_RXNE)!=RESET && Jieshou == 1)             //接收中断  
  127.                 {
  128. //                        OLED_ShowSignedNum(1,1,520,4);
  129.                                 USART_ClearITPendingBit(USART3,USART_IT_RXNE);   //清除中断标志
  130.                                 com_data = USART_ReceiveData(USART3);
  131.                         if(Jieshou == 1)
  132.                         {
  133.                
  134.                                 if(RxState==0&&com_data==0x2C)  //0x2c帧头
  135.                                 {
  136.                                         RxBuffer1[RxCounter1++]=com_data;
  137.                                         RxState=1;
  138.                                 }
  139.                
  140.                                 else if(RxState==1&&com_data==0x12)  //0x12帧头
  141.                                 {
  142.                                         RxBuffer1[RxCounter1++]=com_data;
  143.                                         RxState=2;
  144.                                 }                       
  145.                                 else if(RxState==2)
  146.                                 {
  147.                                         RxBuffer1[RxCounter1++]=com_data;
  148.                                         if(RxCounter1>=14||com_data == 0x5B)       //RxBuffer1接受满了,接收数据结束
  149.                                         {
  150.                                                 RxState=3;
  151.                                                 RxFlag1=1;
  152.                                                 Jieshou = 2;
  153.                                                
  154.                                                 Cx1=RxBuffer1[RxCounter1-9];
  155.                                                 Cy1=RxBuffer1[RxCounter1-8];
  156.                                                
  157.                                                 Cx2=RxBuffer1[RxCounter1-7];
  158.                                                 Cy2=RxBuffer1[RxCounter1-6];
  159.                                                
  160.                                                 Cx3=RxBuffer1[RxCounter1-5];
  161.                                                 Cy3=RxBuffer1[RxCounter1-4];
  162.                                                
  163.                                                 Cx4=RxBuffer1[RxCounter1-3];
  164.                                                 Cy4=RxBuffer1[RxCounter1-2];
  165.                                                
  166.                                                 OLED_ShowSignedNum(1,1,Cx1,4);
  167.                                                 OLED_ShowSignedNum(2,1,Cy1,4);
  168.                                                 OLED_ShowSignedNum(3,1,Cx2,4);
  169.                                                 OLED_ShowSignedNum(4,1,Cy2,4);
  170.                                                
  171.                                                 OLED_ShowSignedNum(1,7,Cx3,4);
  172.                                                 OLED_ShowSignedNum(2,7,Cy3,4);
  173.                                                 OLED_ShowSignedNum(3,7,Cx4,4);
  174.                                                 OLED_ShowSignedNum(4,7,Cy4,4);
  175.                                                
  176.                                         }
  177.                                 }
  178.                         }
  179.                                 else if(RxState==3)                //检测是否接受到结束标志
  180.                                 {
  181.                                         if(RxBuffer1[RxCounter1-1] == 0x5B)
  182.                                         {
  183.                                                 USART_ITConfig(USART3,USART_IT_RXNE,DISABLE);//关闭DTSABLE中断
  184.                                                 if(RxFlag1)
  185.                                                 {       
  186.                                                        
  187.                                                         AngFlag=0;
  188.                                                         HuanRaoZuoBiao();
  189. //                                                                               
  190. //                                                        OLED_ShowSignedNum(1,1,Cx1,4);
  191. //                                                        OLED_ShowSignedNum(2,1,Cx2,4);
  192. //                                                        OLED_ShowSignedNum(3,1,avel_X1,4);
  193. //                                                        OLED_ShowSignedNum(4,1,Cx5[0],4);
  194.                                                         AngFlag=1;
  195.                                                         RxFlag1 = 0;
  196.                                                         RxCounter1 = 0;
  197.                                                         RxState = 0;                                                                       
  198.                                                 }
  199.                                                 USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);                                                                       
  200.                                         }
  201.                                         else   //接收错误
  202.                                         {
  203.                                                                 RxState = 0;
  204.                                                                 RxCounter1=0;
  205.                                                                 for(i=0;i<10;i++)
  206.                                                                 {
  207.                                                                                 RxBuffer1[i]=0x00;      //将存放数据数组清零
  208.                                                                 }
  209.                                         }
  210.                                 }
  211.        
  212.                                 else   //接收异常
  213.                                 {
  214.                                                 RxState = 0;
  215.                                                 RxCounter1=0;
  216.                                                 for(i=0;i<10;i++)
  217.                                                 {
  218.                                                                 RxBuffer1[i]=0x00;      //将存放数据数组清零
  219.                                                        
  220.                                                 }
  221.                                 }
  222.                        
  223.                 }
  224.         }
复制代码
 注意观察下面这副代码截图:

以上便是我对电赛期间OPENMV与单片机之间实现串口通讯的代码实现。学者若有疑问或需要代码工程,可以私聊我。收到后我会及时回复。



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

杀鸡焉用牛刀

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表