例程讲解-02-spi_control spi控制
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)
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)
time.sleep_ms(120)
write_command(0x36, 0xC0)
write_command(0x3A, 0x05)
write_command(0x29)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA2)
sensor.skip_frames(time = 2000)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
write_command(0x2C)
write_image(img)
print(clock.fps())
星瞳科技OpenMV官方中文文档函数讲解: