SPI_Asm vs. SPI_Spin
kolyur
Posts: 43
Are these objects designed to be interchangeable? One runs in a new cog and the other doesn't, but they both have Start, Shiftin, and Shiftout functions with the same parameters. The reason I ask is that SPI_Spin works for me but SPI_Asm doesn't.
I'm communicating with an AD7705 analog-to-digital converter. My basic data transfer functions are:
Basically I write an 8-bit command value, then read in a 16-bit data value (no simultaneous transfers). Using SPI_Spin, everything works great. But if I just change the object definition to SPI_Asm, my readback value becomes some seemingly random number that doesn't change with the signal. I'd really like to figure out how to use the Assembly code here because a clock pulse with Spin code seems to be limited to about 10 us. The AD7705 is capable of much faster transfers so I'd like to use a clock pulse around 1us (which equates to a Delay value of 15 in SPI_Asm).
Are there any modifications I need to make to my code when switching to the Assembly version?
I'm communicating with an AD7705 analog-to-digital converter. My basic data transfer functions are:
PRI WriteToReg(Value) spi.shiftout(TXpin, Cpin, SPI#MSBFIRST, 8, value) PRI ReadResult : Value value := spi.shiftin(RXpin, Cpin, SPI#MSBPOST, 16)
Basically I write an 8-bit command value, then read in a 16-bit data value (no simultaneous transfers). Using SPI_Spin, everything works great. But if I just change the object definition to SPI_Asm, my readback value becomes some seemingly random number that doesn't change with the signal. I'd really like to figure out how to use the Assembly code here because a clock pulse with Spin code seems to be limited to about 10 us. The AD7705 is capable of much faster transfers so I'd like to use a clock pulse around 1us (which equates to a Delay value of 15 in SPI_Asm).
Are there any modifications I need to make to my code when switching to the Assembly version?
Comments
I don't have a pull-up/down on the clock line. I realize there is the possibility of stray data at startup before the Prop sets the pin directions, but my first action afterwards is to reset the chip by sending logic high for 32 pulses (see p.16 of datasheet).
I have the initial clock state set as high (State=1).
But now I have another issue. It seems that when using SPI_Asm, the clock delay value has no effect. I'm referring to the first parameter in the Start method, which I assume to be the length of a clock pulse. In SPI_Spin, the clock delay is in units of microseconds, and of course I can see a noticeable change in my update rate when I change that value. (I'm averaging a fixed number of samples together and then updating my VFD display.)
But with SPI_Asm, that delay seems fixed at about 10-15 us. I estimated that value by comparing the apparent update rate to what I get from SPI_Spin. I scoured my program looking for anything that might be introducing a delay, but it's pretty simple. I don't know enough about assembly to do the same with SPI_Asm.
I'm using a 5Mhz crystal on the Prop if that makes a difference, and I have _clkmode = xtal1 + pll16x, _xinfreq = 5_000_000.
So, there isn't much to be gained by using SPI_Asm and that's why it appeared [to me] to not be working correctly. With the Spin version and a clock pulse of 10us, it takes about 0.5 ms for one data transfer cycle. That's a pretty small fraction of 20 ms so I'll probably stick with SPI_Spin.
Thanks for all your help with this.