|< in Spin
Erlend
Posts: 612
I thought I had it figured out:
Erlend
IF INA[PINmiso]== 1 Framerx |= |<bitpos-that this would put a '1' into Framerx at the bit postion given by the number held by the variable 'bitpos'?
Erlend
Comments
-Phil
Erlend
This is the core method to do SPI, as part of my SPI protocol object:
-and the bug was that at first was written as:
Now it all works fine.
Erlend
You can likely even drop the "& 1" from the end.
In your version, you're ANDing FRAMEtx and (1 << bitpos) together, then testing if the result is > 0, and setting a bit in OUTA based on that. (four operations total - the shift, the AND, the test, and the set)
In my version, FRAMEtex is shifted down so the desired bit is now at bit zero, then you're ANDing with a constant (1). The result doesn't have to be tested - you can just set the result. (three operations total - the shift, the AND, then the set). I believe the "& 1" is optional because in Spin, setting bit with a statement like "OUTA[pin] := x" only uses the low bit of x. Test it to be sure, but I think that's correct. If it is, your overall transfer rate will improve.
Jason
Thanks!
I will implement this change.
I am curious if '1<<bitpos' is the exact same execution as '|<bitpos'? I understand the outcome is the same, but is the |< more efficient?
Erlend
-Phil
Me too. It turns out that the Spin operator is faster than the conventional code, but the conventional code is easier for those that are not yet proficient in Spin.
That's a good point. I do think readability of the code is important.
Erlend