I am trying to program a PLL device with SPI on the RPI using spidev inside Python. I want to rewrite all the values inside the registers on the AD9553 device to allow for a very specific configuration. So far I have calculated all the necessary values to store in the registers for my specific configuration, I have kept these binary values in an array ready to send later. First an instruction bit must be sent to the device defining whether you would like to read or write and if you want to operate in streaming mode, in this case yes as I want to start from register 0x34 and end at 0x00 rewriting all registers in the process. The device should theoretically receive the 16 bit instruction command and then receive the successive 52 - 8 bit commands successively buffering them in the register, I then administer an I/O update in register 5 causing the registers to be loaded thus taking into effect. I am confident that these register values are correct.
However I have some significant doubts: 1) At the moment I am using "Xfer2()" to transfer the bytes from the PI to the device, I dont know if this is the correct command since there is write bytes and "Xfer()" as well. 2) It seems the PI is transmitting from the MOSI pin this is connected to the SDIO pin on the AD9553, I am not completely sure how this works. 3) I do not understand the syntax in Spidev I have read through the documentation and the code but it does not seem to clear up any doubts 4) I am using a for loop in Python to transfer all the bytes from the Reg_Store array to the device (not sure if this is the correct approach) 5) I am not sure what to set for the parameters of the SPI device i.e (threewire mode, max clock speed, etc)
Methods I have approached 1) Splitting up the instruction into two 8 bits and then sending all 52 register after (inside a for loop) 2) Forcing the Chip Select to Low in the loop 3) Messing around with spi.max_speed 4) Trying to send the entire list of values in one line 5) writebytes and xfer
I have previously used Spidev to communicate with an ADC, however it was far easier as you just sent two bytes and then you would receive back the two bytes of information, like a shift register. This works so I know I do not have a problem with my Pi or the SPI.
I am hoping someone with experience will be able to point out directly what I am doing wrong, I look forward to receiving replies.
The datasheet is below and attached is my code.
Many Thanks for reading this.
#!/usr/bin/env python import RPi.GPIO as GPIO import time import sys import spidev import Tkinter # Setup SendDataLED = 11 FinishLED = 13 ChipSel = 24 GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(FinishLED, GPIO.OUT) GPIO.setup(SendDataLED, GPIO.OUT) GPIO.setup(ChipSel, GPIO.OUT) High = GPIO.HIGH Low = GPIO.LOW spi = spidev.SpiDev() spi.open(0,0) # Open an SPI port bus = 0 , device = 0 print spi.mode #spi.max_speed_hz = 100000 #spi.threewire() # Setup Complete # Constants and Variables Nil = 0b00000000 R = [None]*53 #0x34 down to 0x00 R = 0b01101000 #0x34 Val ? R = Nil #0x33 R = 0b10101001 #0x32 R = Nil #0x31 R = Nil #0x30 R = Nil #2F R = Nil #2E R = Nil #2D R = Nil #2C R = Nil #2B R = Nil #2A R = 0b01100000 #0x29 R = Nil #0x28 R = 0b01000000 #0x27 R = Nil #0x26 R = 0b10100000 #0x25 R = 0b01100010 #0x24 R = 0b00001001 #0x23 R = Nil #0x22 R = 0b10100000 #0x21 R = 0b01100010 #0x20 R = 0b00001001 #0x1F R = Nil #0x1E R = Nil #0x1D R = Nil #0x1C R = 0b10000000 #0x1B R = Nil #0x1A R = Nil #0x19 R = 0b00100000 #0x18 R = 0b01110101 #0x17 Starred R = 0b11000000 #0x16 R = 0b00000001 #0x15 R = 0b00001100 #0x14 Starred R = 0b01000101 #0x13 R = 0b00110011 #0x12 R = Nil #0x11 R = 0b10000000 #0x10 R = 0b10000000 #0x0F R = 0b01110000 #0x0Ev Starred R = Nil #0x0D R = Nil #0x0C R = 0b10110000 #0x0B Starred R = 0b10000000 #0x0A R = Nil #0x09 R = Nil #0x08 R = Nil #0x07 R = Nil #0x06 R = 0b00000000 # I/O UPDATE Starred needs to be sent last?? (R:x) R = 0b00000001 # Readback Control Starred R = Nil #0x03 R = Nil #0x02 R = Nil #0x01 R = 0b00011000 #0x00 SPI Control Starred # End of Constants declarations def IOUpdate(MSB_First): #Send the instruction to initiate I/O update if (MSB_First == True): IOUpdateInstr = 0b0000000000000101 #16 Bit instruction for IO Update XFER_IO = spi.xfer2([IOUpdateInstr]) R = 0b00000001 # set the I/O update bit high IO = spi.xfer2([R]) # Send the register print "IO Updated with MSB First" elif (MSB_First == False): IOUpdateInstr = 0b1010000000000000 #16 Bit instruction for IO Update XFER_IO = spi.xfer2([IOUpdateInstr]) R = 0b10000000 # set the I/O update bit high IO = spi.xfer2([R]) # Send the register print "IO updated with LSB First" # ********** Program begin ************* ##Initiate = raw_input("Enter 'go' to start the transfer: ") ##if (Initiate == "go"): ## print "Initiating Transfer" # Define some instructions Instr = 0b0110000000110100 #16 Bit Instruction for loading all registers InstrCut1 = 0b01100000 InstrCut2 = 0b00110100 IOUpdateInstr = 0b0000000000000101 #16 Bit instruction for IO Update IOUpdateCut1 = 0b00000000 IOUpdateCut2 = 0b00000101 Buffer = [None]*55 Buffer = InstrCut1 #first element is instruction Buffer = InstrCut2 #print len(Buffer) for i in range(54,1,-1): #print "Buffer: " + str(56-i) + " Register: " + str(i-2) Buffer[56-i] = R[i-2] Buffer.append(IOUpdateCut1) # append the IO update instruction bit Buffer.append(IOUpdateCut2) Buffer.append(0b00000001) # send the new register value to invoke the io update print Buffer #print Buffer #print Buffer #print "Buffer element: " + str(Buffer) #print "Register element: " + str(R) GPIO.output(ChipSel, Low) for i in range(0,len(Buffer)): #print Buffer[i] GPIO.output(ChipSel, Low) XFER = spi.xfer2([Buffer[i]]) GPIO.output(ChipSel, Low) #time.sleep(0.1) GPIO.output(ChipSel, High) print " \nComplete" #print R print "End Program" spi.close() # closes the comms link with the SPI Device