三木社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 388|回复: 0
打印 上一主题 下一主题

SPI

[复制链接]

1657

主题

1684

帖子

5684

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5684
跳转到指定楼层
楼主
发表于 2017-7-12 08:25:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. from machine import Pin, SPI
  2. # construct an SPI bus on the given pins
  3. # polarity is the idle state of SCK
  4. # phase=0 means sample on the first edge of SCK, phase=1 means the second
  5. spi = SPI(baudrate=100000, polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4))
  6. spi.init(baudrate=200000) # set the baudrate
  7. spi.read(10)            # read 10 bytes on MISO
  8. spi.read(10, 0xff)      # read 10 bytes while outputing 0xff on MOSI
  9. buf = bytearray(50)     # create a buffer
  10. spi.readinto(buf)       # read into the given buffer (reads 50 bytes in this case)
  11. spi.readinto(buf, 0xff) # read into the given buffer and output 0xff on MOSI
  12. spi.write(b'12345')     # write 5 bytes on MOSI
  13. buf = bytearray(4)      # create a buffer
  14. spi.write_readinto(b'1234', buf) # write to MOSI and read from MISO into the buffer
  15. spi.write_readinto(buf, buf) # write buf to MOSI and read MISO back into buf
复制代码


回复

使用道具 举报

Archiver|手机版|小黑屋|三木电子社区 ( 辽ICP备11000133号-4 )

辽公网安备 21021702000620号

GMT+8, 2026-3-6 00:08 , Processed in 0.025258 second(s), 22 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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