SPIcmd vs Shiftout

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
Post Reply
rich
Posts: 81
Joined: 19 November 2015, 12:23 PM

SPIcmd vs Shiftout

Post by rich »

If i am only shifting out 8 bits to a '595 register which of these is fastest:

1)
call pinLow(SHIFT_LAT) ' CS low
call shiftOutEx(SHIFT_DOUT, SHIFT_CLK, 8, tmp, &h01)
' LSB first, Fast, No timer used
call pinHigh(SHIFT_LAT) ' CS high

2)
SPIcmd(1,1,tmp,0,0) 'Given the CS pin was in the
SPIopen statement.
Thanks
Richard
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: SPIcmd vs Shiftout

Post by dkinzer »

rich wrote:If i am only shifting out 8 bits to a '595 register which of these is fastest?
I'm guessing that the ShiftOutEx() might be slightly faster.

I would suggest setting up a test loop where you execute each sequence 100 or 1000 times and measuring the elapsed time. The elapsed time can be measured by zeroing Register.RTCStopWatch before the loop and then reading it after the loop.
- Don Kinzer
rich
Posts: 81
Joined: 19 November 2015, 12:23 PM

Post by rich »

Thanks for the help.

Richard
rich
Posts: 81
Joined: 19 November 2015, 12:23 PM

Post by rich »

Do i did a loop test comparing SHiftOutEX with SPICmd.

The loop went 1000 times for each and used the RTCStopWatch to time the loops.

For 1 byte:
ShiftOutEx = 22
SPICmnd = 23

For 2 bytes:
ShiftOutEx = 52
SPICmd = 25

So if speed is important and you have more than one byte to transfer then SPI is the way to go.

Richard
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

As I surmised, ShiftOutEx is slightly faster for one byte. The reason that SPI is faster for multiple bytes is that it is done by the hardware.
- Don Kinzer
Post Reply