SPIN performance
ftkalcevic
Posts: 10
Sorry if this has been discussed elsewhere, but I just can't get this forum's search to work for me.
I'm trying to write an SPI slave implementation in SPIN, but the data I'm receiving isn't anything like what appears on the wire.· This is a stripped down version of my code...
· repeat
··· b := 0
··· repeat until ina[noparse][[/noparse]nCS_PIN] == 1
··· repeat until ina[noparse][[/noparse]nCS_PIN] == 0
··· repeat 32
····· b <<= 1
····· repeat until ina[noparse][[/noparse]SCK_PIN] == 0
····· repeat until ina[noparse][[/noparse]SCK_PIN] == 1
····· if ina[noparse][[/noparse]MOSI_PIN] == 1
······· b |= 1
··· vt100.PrintHex( b, 8 )
··· vt100.PrintString(string(13))
···
I wait for CS to go low, then read the bits as the clock goes high.·
The SPI is clocked at 125kHz.· Is this too much for SPIN?· Do I need to use PASM (when I get it working I want to up the clock to 1MHz)
Thanks,
Frank
·
I'm trying to write an SPI slave implementation in SPIN, but the data I'm receiving isn't anything like what appears on the wire.· This is a stripped down version of my code...
· repeat
··· b := 0
··· repeat until ina[noparse][[/noparse]nCS_PIN] == 1
··· repeat until ina[noparse][[/noparse]nCS_PIN] == 0
··· repeat 32
····· b <<= 1
····· repeat until ina[noparse][[/noparse]SCK_PIN] == 0
····· repeat until ina[noparse][[/noparse]SCK_PIN] == 1
····· if ina[noparse][[/noparse]MOSI_PIN] == 1
······· b |= 1
··· vt100.PrintHex( b, 8 )
··· vt100.PrintString(string(13))
···
I wait for CS to go low, then read the bits as the clock goes high.·
The SPI is clocked at 125kHz.· Is this too much for SPIN?· Do I need to use PASM (when I get it working I want to up the clock to 1MHz)
Thanks,
Frank
·
Comments
Spin is going at something like 100 instructions per statement, last I heard.
Perhaps using waitpeq and friends to wait for pin states rather than repeat loops would do it in Spin (see the manual).
For 1MHz definitely PASM.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Originally I used waitpeq, but got the same results. I'll start playing around with PASM.
That's just exactly 4 instructions for Tx and 4 for Rx on an 80MHz Prop. Just works nicely.
I guess there is a SPI driver or two in OBEX. You could look at those to see how the bit sampling goes even if they are the master end. Have a look at the SD card low level driver in FSRW.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
b +=b is the same as multiplying by two, which is the same as SHL by 1. And adding the actual value of the bit adds a 1 if the bit is high, and adds a 0 if it's low. You may want to check for CLK hi, then do the above line, then check for CLK low, then let it repeat, that way the overhead of the repeat can be concurrent with the CLK pin being low.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.