SPI_Asm, shiftout more than 8 bits
randreas
Posts: 2
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?
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?
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
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