OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4180|回复: 3

关于STM32F1与OpenMV通讯的问题

[复制链接]

1

主题

2

帖子

0

精华

新手入门

积分
4
金钱
4
注册时间
2021-11-15
在线时间
0 小时
发表于 2021-11-15 00:18:05 | 显示全部楼层 |阅读模式
1金钱
在OpenMV上配置,当识别到黄色时,通过UART.Write('1')

再通过STM32串口中断接收

其中OpenMv的RX接STM32的TX端
然后OpenMv的TX接STM32的RX端
最后其中OpenMv的GND接STM32的GND端
但是STM32没有办法接收到数据?这是为什么呢?
在其中OpenMv与STM32通讯之前,我尝试过OpenMv与电脑通讯,在串口助手上可以正常显示1,然后尝试过STM32显示,都可以正常运行,请问问题在哪里呢?
最后附上STM32的串口配置



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

2

帖子

0

精华

新手入门

积分
4
金钱
4
注册时间
2021-11-15
在线时间
0 小时
 楼主| 发表于 2021-11-15 00:26:24 | 显示全部楼层
补充:OpenMv的程序,程序目的是想让OpenMv识别到黄色后向串口发送‘1’,当识别到黄色时,串口助手则接收1(已验证)
  1. # Blob Detection and uart transport
  2. import sensor, image, time
  3. from pyb import UART
  4. import json
  5. # For color tracking to work really well you should ideally be in a very, very,
  6. # very, controlled enviroment where the lighting is constant...
  7. yellow_threshold   = (19,34,20,40,16,35)
  8. # You may need to tweak the above settings for tracking green things...
  9. # Select an area in the Framebuffer to copy the color settings.

  10. sensor.reset() # Initialize the camera sensor.
  11. sensor.set_pixformat(sensor.RGB565) # use RGB565.
  12. sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
  13. sensor.skip_frames(10) # Let new settings take affect.
  14. sensor.set_auto_whitebal(False) # turn this off.
  15. clock = time.clock() # Tracks FPS.

  16. uart = UART(3, 115200)
  17. def find_max(blobs):
  18.     max_size=0
  19.     for blob in blobs:
  20.         if blob.pixels() > max_size:
  21.             max_blob=blob
  22.             max_size = blob.pixels()
  23.     return max_blob

  24. while(True):
  25.     img = sensor.snapshot() # Take a picture and return the image.

  26.     blobs = img.find_blobs([yellow_threshold])
  27.     if blobs:
  28.         max_blob=find_max(blobs)
  29.         print('sum :', len(blobs))
  30.         img.draw_rectangle(max_blob.rect())
  31.         img.draw_cross(max_blob.cx(), max_blob.cy())

  32.         #output_str="[%d,%d]" % (max_blob.cx(),max_blob.cy()) #方式1
  33.         #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
  34.         #print('you send:',output_str)a
  35.         uart.write('1')
  36.         print('write1')
  37.     else:
  38.         print('not found!')
复制代码
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165537
金钱
165537
注册时间
2010-12-1
在线时间
2117 小时
发表于 2021-11-16 02:44:29 | 显示全部楼层
帮顶
回复

使用道具 举报

0

主题

32

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
4057
金钱
4057
注册时间
2019-4-2
在线时间
282 小时
发表于 2021-11-17 13:23:20 | 显示全部楼层

python
------------------------------------------
import sensor, image, time, math, pyb
from pyb import UART,LED
import json
import ustruct

RED_LED_PIN = 2

uart = UART(3,115200)   #定义串口3变量
uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters


#stm32_pa9  对 openmv_p5
#stm32_pa10 对 openmv_p4
while(True):

    if(uart.any()):
        d=uart.readline();   #读串口数据
        c=d.decode('uft-8');
        print(d)
        if(c=="1\r\n"):
            cx=0;cy=3;length=0;
            FH = bytearray([0x2C,0x12,cx,cy,length,0x5B])
            uart.write(FH)
            print(FH)
            pyb.LED(RED_LED_PIN).on()
            time.sleep(20)
            pyb.LED(RED_LED_PIN).off()
            time.sleep(20)
--------------------------------------------------------------------
stm32
--------------------------------------------------------------------
void usartSendStr(USART_TypeDef* USARTx,char *str)
{
        uint16_t i = 0;
        do{
                usartSendByte(USARTx,*(str+i));
                i++;
        }while(*(str+i) != '\0');

        while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}

int main(void)
{               

                OLED_Init();
                delay_init();                                                  //延时函数初始化          
                NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);   //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
                USART1_Init();
                //OLED_ColorTurn(0);          //0正常显示,1 反色显示
                //OLED_DisplayTurn(0);        //0正常显示 1 屏幕翻转显示
while(1)
        {
                usartSendStr(USART1,"1\r\n");
                delay_ms(50);
        }

               
       
}

回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-15 05:01

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表