简体   繁体   English

OpwenWrt-使用Python从SPI读取字节

[英]OpwenWrt - reading byte from SPI with Python

I want to read bytes from the spi bus. 我想从spi总线读取字节。 Writing a byte is simple by just using 只需使用一个字节即可写入字节

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

I tried using the read(1) command, but this makes the spi clock way longer than just for one byte. 我尝试使用read(1)命令,但是这使spi时钟的方式比一个字节更长。

Example: 例:

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

Does anyone have a clue why it just doenst clock 8 times when I try to read one byte? 有谁知道为什么当我尝试读取一个字节时它只会时钟8次?

(I am using a Carambola2 by the way and the spi over gpio) (顺便说一句,我正在使用Carambola2,并且在SPI上使用SPI)

I solved the Problem on my own. 我自己解决了问题。 You have to use the os library 您必须使用os库

Example: 例:

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))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM