SPI for LTC2664 in PASM
Dave Matthews
Posts: 93
in Propeller 1
I am trying to control this 4 channel A>D converter using the SPI protocol. I have successfully used the SPIN version written by Ryan David to control this chip, it works great. http://obex.parallax.com/object/375 Unfortunately it is too slow for my needs. I have tried the PASM version written by Beau Schwabe, but I can't see a way for it to properly toggle the chip select pin. I have never done any asm programming on the Propeller, so I would be grateful for a code snippet or other advice and instructions.
Dave
This is the code that works properly in SPIN:
Dave
This is the code that works properly in SPIN:
VAR byte CS, SCK, SDI PUB Init(inCS, inSCK, inSDI) CS := inCS SCK := inSCK SDI := inSDI dirA[SDI]~~ dirA[SCK]~~ dirA[CS]~~ outA[CS] := 1 outA[SCK] := 0 PUB Set(Value) | data data := Value data ><= 24 outa[CS] := 0 repeat 24 outa[SDI] := data & 1 outa[SCK] := 1 outa[SCK] := 0 data >>= 1 outA[CS] := 1
Comments
http://obex.parallax.com/object/799
Thanks for the response Mark_T
I didn't study your code at all but you may try to cognew, init, setup using the -w testconvert.cog.spin version and see if anything happens.
SPI : "testconvert.cog.spin" put in OBJ section
In your main program start the cog with
SPI.__cognew
SPI.Init(Incs, Insck, Insdi) ' send the pins
SPI.Set(Value) ' put in a value to send
BTW it took about 30 seconds to make these files:
CD\ to the folder
launch terminal prompt
type fastspin -w testconvert.spin
It outputs the converted file in less than a second. You can see how I launched it in the terminal.
After a brief bit of experimenting I am pretty sure I don't have any timing issues. The LTC2664 data sheet specifies the SPI clock rates up to 50MHz. I have a really neat scope, a Siglent SDS1202X-E that has a mode to decode SPI data streams, made it easy to ensure I was assembling the code words correctly.
Fastspin does generate a large amount of code, that doesn't concern me at this stage. After I get the entire application working I will hopefully write an efficient PASM routine to to this simple SPI job.
Thanks so much for the information you shared and your time, very much appreciated!
Dave