sdahman
Posts: 7
Joined: Tue Jul 09, 2019 3:57 am

LMX2594 programming using Python and Raspberry PI

Tue Jul 09, 2019 4:11 am

hello,

I am trying to use the Raspberry pi B + to program a SPI based device.

I did not used spidev could you please advise me on how to write 3 bytes using spidev?, I tried many times, but it seems that it did not work for me, when I print a write command, it show all 0's and when I apply the write command that supposed to read back registers contents, I get 0's as well,
I attached the write and read that the device understands, I think my issue is the python commands

I would highly appreciate your support

B.R.
sdahman
Attachments
readback register.PNG
readback register.PNG (56.41 KiB) Viewed 461 times
write register.PNG
write register.PNG (67.44 KiB) Viewed 461 times

User avatar
MrYsLab
Posts: 353
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: LMX2594 programming using Python and Raspberry PI

Tue Jul 09, 2019 3:46 pm

You might want to check out the examples on the pigpio python examples page: http://abyz.me.uk/rpi/pigpio/examples.h ... hon%20code
Although not specific to the LMX2594, there are several SPI examples and perhaps they may give you some ideas.

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: LMX2594 programming using Python and Raspberry PI

Tue Jul 09, 2019 4:42 pm

spidev is explained in many places, see this as a starter: https://pypi.org/project/spidev/
xfer2 is usually a good choice if chip select is needed.
Please post your current code, makes it easier to understand your problems.

sdahman
Posts: 7
Joined: Tue Jul 09, 2019 3:57 am

Re: LMX2594 programming using Python and Raspberry PI

Wed Jul 10, 2019 4:23 am

thanks for the replies

this is a simple code to write 3 bytes, but I am getting back 0's

import spidev
spi = spidev.SpiDev()
spi.open(bus, device)
to_send = [0x01, 0x02, 0x03]
spi.xfer(to_send)

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: LMX2594 programming using Python and Raspberry PI

Wed Jul 10, 2019 5:02 am

Although there are reports saying that xfer and xfer2 do the same, i'd recommend using xfer2 when CS is needed active during the whole transaction. https://embeddedmicro.weebly.com/spi.html
When I look into the datasheet if the "LMX2594 15-GHz Wideband RF Synthesizer", there is no serial data out or alike. Seems to be a write only device. Not to be expected to get data back. How is your board connected to which pins of the PI ?

Edit: just see there is a MUXout pin which is controlled by MUXOUT_LD_SEL.

sdahman
Posts: 7
Joined: Tue Jul 09, 2019 3:57 am

Re: LMX2594 programming using Python and Raspberry PI

Thu Jul 11, 2019 2:27 am

i connect pin2 to CE0
pin3 to MISO
pin4 to MOSI
pin8 to SCLK
Attachments
SPI_HW.PNG
SPI_HW.PNG (191.81 KiB) Viewed 370 times

sdahman
Posts: 7
Joined: Tue Jul 09, 2019 3:57 am

Re: LMX2594 programming using Python and Raspberry PI

Thu Jul 11, 2019 2:43 am

this is my entire code

import RPi.GPIO as GPIO
import spidev
import struct
import time

# for GPIO numbering, choose BCM
GPIO.setmode(GPIO.BCM)
spiLMX = spidev.SpiDev()
spiLMX.open(0,0)
spiLMX.mode = 0x00
#resp = spiLMX.writebytes([0x00251C])
resp = spiLMX.xfer2([0x3, 0x8, 0xA, 0x4, 0x0, 0x0])
#resp2 = spiLMX.writebytes([0x002518])
resp2 = spiLMX.xfer2([0x1, 0x8, 0xA, 0x4, 0x0, 0x0])
#resp3 = spiLMX.writebytes([0x80])
resp3 = spiLMX.xfer2([0x0, 0x1])
print (resp)
print (resp2)
print (resp3)
spiLMX.close()

here is the output
Attachments
SPI_read_write_output.PNG
SPI_read_write_output.PNG (35.47 KiB) Viewed 368 times

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: LMX2594 programming using Python and Raspberry PI

Thu Jul 11, 2019 5:11 pm

Read/ writes for the chip are according to the sheet always 24 bits, address and 16 bits of data.
I do not have this chip here, so following the datasheet the process is
- reset chip, remove reset.
- write the 'MUXOUT bit in register 0
- read back register 0, just for tests.

Code: Select all

import spidev

# for GPIO numbering, choose BCM
spiLMX = spidev.SpiDev()
# rather low in order not to challenge connections. Device can up to 50MHz
spiLMX.max_speed_hz = 1000000
spiLMX.open(0,0)
spiLMX.mode = 0x00

def transferWrite( c, reg, dataH, dataL):
    spiLMX.xfer2([reg, dataH, dataL])
    print("write", c)
    
def transferRead( c, reg):
    regW = reg | 0b10000000
    resp = spiLMX.xfer2([regW, 0, 0])
    print("read ", c, resp)

transferWrite( "reset 1", 0, 0b00000000, 0b00000010 ) 
transferWrite( "reset 0", 0, 0b00000000, 0b00000000 ) 
transferWrite( "MUXOUT ", 0, 0b00000000, 0b00000100 )
transferRead ( "MUXOUT ", 0 )
 
spiLMX.close()
Not tested. maxspeed is set lower than the allowed 50 MHz, just to allow slow wires to follow the signals.
Close the muxout switch on the board. Check signals using a logic analyzer. Could be that 'mode' needs to be changed.

sdahman
Posts: 7
Joined: Tue Jul 09, 2019 3:57 am

Re: LMX2594 programming using Python and Raspberry PI

Fri Jul 12, 2019 4:07 am

i got this error, but I am surprised it complained about the speed, what should i do?

thanks
sdahman
Attachments
max spped error.PNG
max spped error.PNG (71.77 KiB) Viewed 317 times

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: LMX2594 programming using Python and Raspberry PI

Fri Jul 12, 2019 4:29 am

perhaps needed to move this max_speed-statement after the spiLMX.open(0,0).

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: LMX2594 programming using Python and Raspberry PI

Sat Jul 13, 2019 4:59 pm

You made a comment in another thread about the topic. The posted lines from you were:
actually i added these lines to your code and i read back something that i did not figure out yet, i wrote

Changed code and output:

transferWrite( "MUXOUT", 0, 0b00000000, 0b00000100 )
transferWrite( "MUXOUT", 0, 0b00100100, 0b00010000 )
transferRead ("MUXOUT", 0 )

i got back those extra outputs
write MUXOUT
write MUXOUT
read MUXOUT [0, 36, 16]
I doublechecked the datasheet and found that the muxout enable bit is '0' (assumed this is '1' earlier). My initial proposal to have transferWrite( "MUXOUT", 0, 0b00000000, 0b00000100 ) to enable muxout would not work.
Your second line transferWrite( "MUXOUT", 0, 0b00100100, 0b00010000 ) writes R0, sets bit 2 to '0' which enables the muxout. Then your third line transferRead ("MUXOUT", 0 ) reads R0 with the content you have written in line 2: 0b00100100= 36, 0b00010000 = 16

This looks good. The chip responds with data on SPI. Now it is up to you to do something useful with this device.

sdahman
Posts: 7
Joined: Tue Jul 09, 2019 3:57 am

Re: LMX2594 programming using Python and Raspberry PI

Sat Jul 13, 2019 10:20 pm

great, thank you so much for helping me, I really appreciate that!

how do I put this thread as resolved?

Return to “Python”