[英]OpwenWrt - reading byte from SPI with Python
我想從spi總線讀取字節。 只需使用一個字節即可寫入字節
file = open("/dev/spidev1.0", 'wb')
file.write('#')
我嘗試使用read(1)命令,但是這使spi時鍾的方式比一個字節更長。
例:
file = open("/dev/spidev1.0", 'rb')
file.read(1)
有誰知道為什么當我嘗試讀取一個字節時它只會時鍾8次?
(順便說一句,我正在使用Carambola2,並且在SPI上使用SPI)
我自己解決了問題。 您必須使用os庫
例:
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.