openmv应该向stm32端传输哪些数据呢
W
wm5r
@wm5r
0
声望
2
楼层
123
资料浏览
0
粉丝
0
关注
wm5r 发布的帖子
-
openmv和stm32通信,但是数据传不过去,请问是什么问题?
大佬们,想问一下我这个哪里有问题啊想让openmv和stm32通信,但是数据传不过去,看ooenmv端的串行终端是打印出来值了的,可是32的lcd显示屏上一直是(0,0),有佬知道是哪里的问题嘛
openmv端:# Untitled - By: zzy - 周五 11月 25 2022 import sensor, image, time from pyb import UART import json #output_str_green="[0,0]" output_str_white="[0,0]" #green_threshold = ( 0, 80, -70, -10, -0, 30) #使用的白色测试阈值 white_threshold = (53, 100, -128, 127, -128, 127) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.set_windowing((0,20,320,200))#QVGA find Region Of Interest #sensor.set_windowing((5,10,160,95))#QQVGA find Region Of Interest sensor.skip_frames(10) sensor.set_auto_whitebal(False)#白平衡增益关闭 clock = time.clock() uart = UART(3, 115200) def find_max(blobs): max_size=0 for blob in blobs: if blob.pixels() > max_size: max_blob=blob max_size = blob.pixels() return max_blob def detect(max_blob):#输入的是寻找到色块中的最大色块 #print(max_blob.solidity()) shape=0 if max_blob.solidity()>0.90 or max_blob.density()>0.84: img.draw_rectangle(max_blob.rect(),color=(255,255,255)) shape=1 elif max_blob.density()>0.6: img.draw_circle((max_blob.cx(), max_blob.cy(),int((max_blob.w()+max_blob.h())/4))) shape=2 elif max_blob.density()>0.4: img.draw_rectangle(max_blob.rect(),color=(0,0,0)) shape=3 return shape while(True): #clock.tick() img = sensor.snapshot() # Take a picture and return the image. blobs_white = img.find_blobs([white_threshold]) if blobs_white: max_blob_white=find_max(blobs_white) shape_white=detect(max_blob_white) #img.draw_rectangle(max_blob_blue.rect(),color=(0,0,255)) img.draw_cross(max_blob_white.cx(), max_blob_white.cy(),color=(0,0,255)) output_str_white="[%d,%d]" % (max_blob_white.cx()-160,max_blob_white.cy()-100) #方式1 img_data=bytearray([0x2C,7,4,max_blob_white.cx()-160,max_blob_white.cy()-100,1,0X5B]) # 数据倒数前三位可发送成功 uart.write(img_data) print('white:',output_str_white) else: print('not found white !') # uart.write(output_str_green + output_str_red + output_str_blue + output_str_brown + output_str_yellow + '\r\n') #print(clock.fps())
stm32端
openmv.c#include "openmv.h" #include "usart.h" int openmv[7];//stm32接收数据数组 int16_t data1; int16_t data2; int16_t data3; int16_t data4; int i=0; void Openmv_Receive_Data(int16_t data)//接收Openmv传过来的数据 { static u8 state = 0; if(state==0&&data==0x2C) { state=1; openmv[0]=data; } else if(state==1&&data==7) { state=2; openmv[1]=data; } else if(state==2) { state=3; openmv[2]=data; } else if(state==3) { state = 4; openmv[3]=data; } else if(state==4) { state = 5; openmv[4]=data; } else if(state==5) { state = 6; openmv[5]=data; } else if(state==6) //检测是否接受到结束标志 { if(data == 0x5B) { state = 0; openmv[6]=data; Openmv_Data(); } else if(data != 0x5B) { state = 0; for(i=0;i<7;i++) { openmv[i]=0x00; } } } else { state = 0; for(i=0;i<7;i++) { openmv[i]=0x00; } } } void Openmv_Data(void) { data1=openmv[0]; data2=openmv[3]; data3=openmv[4]; data4=openmv[5]; }
usart.c
#include "sys.h" #include "usart.h" #include "openmv.h" //如果使用ucos,则包括下面的头文件即可. #if SYSTEM_SUPPORT_OS #include "includes.h" //ucos 使用 #endif // //加入以下代码,支持printf函数,而不需要选择use MicroLIB #if 1 #pragma import(__use_no_semihosting) //标准库需要的支持函数 struct __FILE { int handle; }; FILE __stdout; //定义_sys_exit()以避免使用半主机模式 void _sys_exit(int x) { x = x; } //重定义fputc函数 int fputc(int ch, FILE *f) { while((USART1->SR&0X40)==0);//循环发送,直到发送完毕 USART1->DR = (u8) ch; return ch; } #endif #if EN_USART1_RX //如果使能了接收 //串口1中断服务程序 //注意,读取USARTx->SR能避免莫名其妙的错误 u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节. //接收状态 //bit15, 接收完成标志 //bit14, 接收到0x0d //bit13~0, 接收到的有效字节数目 u16 USART_RX_STA=0; //接收状态标记 //初始化IO 串口1 void uart_init(u32 bound){ //GPIO端口设置 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE); //使能USART1,GPIOA时钟以及复用功能时钟 //USART1_TX PA.9 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出 GPIO_Init(GPIOA, &GPIO_InitStructure); //USART1_RX PA.10 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入 GPIO_Init(GPIOA, &GPIO_InitStructure); //Usart1 NVIC 配置 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器 //USART 初始化设置 USART_InitStructure.USART_BaudRate = bound;//一般设置为9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式 USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位 USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式 USART_Init(USART1, &USART_InitStructure); //初始化串口 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启中断 USART_Cmd(USART1, ENABLE); //使能串口 printf("usart1_init_success\r\n"); } void USART1_IRQHandler(void) //串口1中断服务程序 { u8 Res; #if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS. OSIntEnter(); #endif if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾) { Res =USART_ReceiveData(USART1);//(USART1->DR); //读取接收到的数据 Openmv_Receive_Data(Res); Openmv_Data(); if((USART_RX_STA&0x8000)==0)//接收未完成 { if(USART_RX_STA&0x4000)//接收到了0x0d { if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始 else USART_RX_STA|=0x8000; //接收完成了 } else //还没收到0X0D { if(Res==0x0d)USART_RX_STA|=0x4000; else { USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ; USART_RX_STA++; if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//接收数据错误,重新开始接收 } } } } #if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS. OSIntExit(); #endif } #endif
main.c
#include "stm32f10x.h" #include "sys.h" #include "delay.h" #include "usart.h" #include "led.h" #include "lcd.h" #include "openmv.h" extern int openmv[7];//stm32接收数据数组 extern int16_t data1; extern int16_t data2; extern int16_t data3; extern int16_t data4; int16_t data; int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2 delay_init(); //初始化延时函数 uart_init(115200); //初始化串口波特率为115200 LED_Init(); //初始化LED LCD_Init(); //初始化LCD FSMC接口 while(1) { LCD_ShowString(30,70,50,50,24,"CX:"); LCD_ShowNum(70,70,data2,5,24); LCD_ShowString(30,120,100,100,24,"Cy:"); LCD_ShowNum(70,120,data3,5,24); delay_ms(150); } }