Shop OBEX P1 Docs P2 Docs Learn Events
SPI_Asm, shiftout more than 8 bits — Parallax Forums

SPI_Asm, shiftout more than 8 bits

randreasrandreas Posts: 2
edited 2014-11-03 11:12 in Propeller 1
Hello,

I'm trying to speed up SPI communications in an ongoing project. In the following code, I have commented out the old spin statements, that worked perfectly - but slow.

Instead I try to use the SPI_Asm object. The SHIFTIN part of it works as expected, if I only change that part.The SHIFTOUT part does not work. I can see on the scope that the latch line goes low after 8 bits, instead of 16 bits that should be sent, while the clock line continues for another 8 bits.

Almost as if the "repeat while command" in the SPI_Asm doesn't behave as it should?

Or am I doing something wrong here?
PRI ShiftOutIn(data_out) : data_in
        'dira[gui_DATA]~~
        'data_out <-= 1
        'repeat 16
        '   outa[gui_DATA] := (data_out ->= 1 )
        '   ' clock cycle
        '   !outa[gui_CLOCK]
        '   !outa[gui_CLOCK]

        spi.SHIFTOUT(2,3,spi#MSBFIRST,16,data_out)

         ' strobe low to latch outputs on 595
        !outa[gui_STROBE]
        !outa[gui_STROBE]

        'dira[gui_DATA]~ 
        ' loop through all inputs and stick into data_in 
        'repeat 8
         '  data_in :=(data_in << 1) + ina[gui_DATA]
          ' !outa[gui_CLOCK]
           '!outa[gui_CLOCK]

        data_in := spi.SHIFTIN(2,3,spi#MSBPRE,8)
        return data_in

This code communicates to two 595s and one 165 on the same data line, but with a 10K resistor to the 165 serial output.

Any thoughts?

Comments

  • twm47099twm47099 Posts: 867
    edited 2014-11-03 10:38
    I see that you are using MSBFIRST. There is an error in that part of the pasm code. The link below shows the error and the fix. I had to make that correction in the pasm code I used in my SimpleIDE C library.

    I can't say that will solve your problem, but it is a place to start.

    Tom

    http://forums.parallax.com/showthread.php?p=1061378#post1061378
  • randreasrandreas Posts: 2
    edited 2014-11-03 10:59
    I have already tried, but no go. LSBFIRST also behaves the same. Here is the scope trace. Note that ch. 2 is the spin code (!OUTA[gui_STROBE]) that executes too soon, as far as I can understand.

    SPI_Asm_scopetrace.jpg
    1024 x 696 - 107K
  • kuronekokuroneko Posts: 3,623
    edited 2014-11-03 11:12
    randreas wrote: »
    Almost as if the "repeat while command" in the SPI_Asm doesn't behave as it should?
    It does in fact work as designed. Problem is that the PASM part clears the command after it fetched all parameters and since SHIFTOUT doesn't return any result it effectively unblocks the SPIN wrapper at this point (SHIFTIN has to wait a bit longer). IOW your enable pulse appears in parallel with the SPI pulse train.
Sign In or Register to comment.