import spidev
import RPi.GPIO as GPIO
import time
def StartUp():
GPIO.setmode(GPIO.BCM)
PRESET = 25
IO4 = 26
GPIO.setup(PRESET,GPIO.OUT)
GPIO.setup(IO4,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print "Reset 25 - Low 1s"
GPIO.output(PRESET,GPIO.LOW)
time.sleep(3)
print "Reset 25 - High 0.2s"
GPIO.output(PRESET,GPIO.HIGH)
time.sleep(0.2)
spi = spidev.SpiDev()
spi.open(0,1)
spi.mode = 0b00
print "spi.cshigh is " + str(spi.cshigh)
print "spi mode is " + str(spi.mode)
spi.max_speed_hz = 200000
print "spi maxspeed is "+str(spi.max_speed_hz)+"hz"
return spi
def TestSPI(spi,ncycles):
i = 0
while i < ncycles:
WriteFPGA(spi,0xEB,0x01)
time.sleep(0.5)
WriteFPGA(spi,0xEB,0x00)
time.sleep(0.5)
i = i+1
def ConfigSPI(spi):
WriteFPGA(spi,0xE0,0x14)
WriteFPGA(spi,0xE1,0x00)
WriteFPGA(spi,0xE2,0xC8)
WriteFPGA(spi,0xE3,0x00)
WriteFPGA(spi,0xE4,0xBC)
WriteFPGA(spi,0xE5,0x00)
WriteFPGA(spi,0xE6,0xC8)
WriteFPGA(spi,0xE7,0x01)
WriteFPGA(spi,0xE8,0x86)
WriteFPGA(spi,0xE9,0xA0)
WriteFPGA(spi,0xEB,0x00)
WriteFPGA(spi,0xEC,0x11)
WriteFPGA(spi,0xED,0x03)
WriteFPGA(spi,0xEE,0xA0)
print "Config FPGA done!"
def WriteFPGA(spi,adress,value):
spi.xfer([0xAA] )
spi.xfer([adress] )
spi.xfer([value] )
int(0x0186A0)
100000
spi = StartUp()
ConfigSPI(spi)
Reset 25 - Low 1s
Reset 25 - High 0.2s
spi.cshigh is False
spi mode is 0
spi maxspeed is 200000hz
Config FPGA done!
WriteFPGA(spi,0xEA,0x01)
WriteFPGA(spi,0xEA,0x00)
while 1:
WriteFPGA(spi,0xEA,0x01)
time.sleep(0.005)
WriteFPGA(spi,0xEE,0xBB)
WriteFPGA(spi,0xEB,0x00)
WriteFPGA(spi,0xEA,0x00)
WriteFPGA(spi,0xEA,0x01)
time.sleep(0.01)
for i in range(1011):
spi.xfer([0xBB] )
print spi.xfer([0x1])
print spi.xfer([0xBB])
time.sleep(0.001)
print spi.xfer([0xBB])
[170]
[170]
[170]
print spi.xfer([0xA1])
print spi.xfer([0xA1])
time.sleep(0.001)
print spi.xfer([0xA1])
[170]
[170]
[170]
ct = []
for i in range(10101):
ct.append( spi.xfer([0x81] )[0] )
last = 0
for j in range(len(ct)):
if not(ct[j] == last):
print last,ct[j]
last = ct[j]
0 170
spi.readbytes(100)
[170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170,
170]
spi.close()