Py学习  »  Python

opwenwrt-使用python从spi读取字节

Elec • 7 年前 • 2080 次点击  

我想从spi总线读取字节。 只需使用

file = open("/dev/spidev1.0", 'wb')
file.write('#')

我试过使用read(1)命令,但这使spi时钟比一个字节长。

例子:

file = open("/dev/spidev1.0", 'rb')
file.read(1)

有人知道为什么当我试图读取一个字节时它只会8次不计时吗?

(顺便说一句,我用的是杨桃,spi是gpio)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39778
文章 [ 1 ]  |  最新文章 7 年前
Elec
Reply   •   1 楼
Elec    7 年前

我自己解决了这个问题。 你必须使用操作系统库

例子:

import os

file = os.open('filename', os.O_RDWR)

#Write byte 0x1 to SPI Bus
os.write(file, chr(0x1))
#Read one byte from SPI Bus
print(str(ord(os.read(file, 1))))