2017-08-13 24 views
0

は、spidevモジュールからループバックテストを実行する方法を理解できません。 提供されたspidev_test.cファイルの実行は機能します。まだPythonではありません。RaspPi 3(ループバック)でSPIを実行しようとしました

import spidev 
import time 

spi = spidev.SpiDev() 
spi.loop = True 
spi.open(0,0) 

try: 
    while True: 
     spi.writebytes([0xAA, 0xFF]) 
     time.sleep(0.01) 
     print(spi.readbytes(2))  
except KeyboardInterrupt: 
    spi.close() 
+0

ので、どのようにバイトを送信すると同時に、それを受け取るために:あなたはこのような何かを探しているLoopback_Testing



spi.loop = True
関連を設定すること自由に感じなさい。 – soderdaen

+0

'spi.writebytes([0xAA、0xFF]); time.sleep(0.01); print(spi.readbytes(2)) ' – stovfl

+0

time.sleep(0.01)行の – soderdaen

答えて

0

Comment: Gives the same output as written in xfer2 just because the function xfer2 returns the values that are given, so not really a confirmation of a working spi

行うことになっているものxfer厥。
出力はspidev_test.cと異なりますか?
利用不可能なportまたはdeviceを使用すると、失敗します。


Comment: spi.loopback() missing

あなたがspi.loopステータスを確認しましたか?私はSPIを確認する方法を意味

import spidev 
import time 

spi = spidev.SpiDev() 
# spidev_test.c uses /dev/spidev1.1 
spi.open(1,1) #use spi Port 1, device (CS) 1 

while True: 
    try: 
     response = spi.xfer2([0xAA, 0xFF]) 
     print(response) 
     time.sleep(1) 
    except KeyboardInterrupt: 
     spi.close() 
+0

関数xfer2が与えられた値を返すだけなので、xfer2で書かれたのと同じ出力が得られます。実際に動作しているSPIの確認ではありません。 プラス:spi.loopback()がありません 、または私はここで完全に間違っていますか? – soderdaen

+0

@soderdaen:更新された自分の回答 – stovfl

関連する問題