例程讲解-02-spi_control spi控制

# SPI 控制
#
# 这个例子展示了,如何使用OpenMV的SPI总线
# LCD 扩展板没有使用内置的lcd驱动。而是使用了SPI。
# 需要插入LCD扩展板来运行这个例子

import sensor, image, time
from pyb import Pin, SPI

cs  = Pin("P3", Pin.OUT_OD)
rst = Pin("P7", Pin.OUT_PP)
rs  = Pin("P8", Pin.OUT_PP)
# # OpenMV上的硬件SPI总线都是2
spi = SPI(2, SPI.MASTER, baudrate=int(1000000000/66), polarity=0, phase=0)

def write_command_byte(c):
    cs.low()
    rs.low()
    spi.send(c)
    cs.high()

def write_data_byte(c):
    cs.low()
    rs.high()
    spi.send(c)
    cs.high()

def write_command(c, *data):
    write_command_byte(c)
    if data:
        for d in data: write_data_byte(d)

def write_image(img):
    cs.low()
    rs.high()
    spi.send(img)
    cs.high()

# 重启
rst.low()
time.sleep_ms(100)
rst.high()
time.sleep_ms(100)

write_command(0x11) # Sleep Exit
time.sleep_ms(120)

# Memory Data Access Control
write_command(0x36, 0xC0)

# 设置 Pixel Format 接口
write_command(0x3A, 0x05)

# 开启显示
write_command(0x29)

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # must be this
sensor.set_framesize(sensor.QQVGA2) # must be this
sensor.skip_frames(time = 2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    write_command(0x2C) # Write image command...
    write_image(img)

    print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.

星瞳科技OpenMV官方中文文档函数讲解:

results matching ""

    No results matching ""