SPI Tutorial_I'm Missing Something
briank77479
Posts: 36
I'm going through the SPI tutorial and typed in the code for the Bit Mask exercise to read the Z-Axis, see below. I thought I checked to make sure I typed in the code correctly, but evidently I didn't. When I run the code all I get is a blank screen; no errors though.
I've run other code to ensure the device is connected correctly and checked that the IDE was configured to my Activityboard. All that appears correct.
I'm sure I'm overlooking something simple but my eyes have glazed over. Would very much appreciate another pair of eyes looking at the code I typed to see what I missed.
Thank you Parallax for these "C" tutorials. They are extremely helpful!!!
I've run other code to ensure the device is connected correctly and checked that the IDE was configured to my Activityboard. All that appears correct.
I'm sure I'm overlooking something simple but my eyes have glazed over. Would very much appreciate another pair of eyes looking at the code I typed to see what I missed.
Thank you Parallax for these "C" tutorials. They are extremely helpful!!!
c
813B
Comments
I haven't used C on the Propeller much myself so I doubt I'll be much help but IMO you'll be more likely to get help if you provide a link to the tutorial you're asking about. I myself am often willing to take a look at code but I'm too lazy to search for a tutorial.
http://learn.parallax.com/propeller-c-simple-protocols/spi-example
Your turn is here:
http://learn.parallax.com/propeller-c-simple-protocols/bit-masks-better-code
Maybe the wires are not connected correctly?
Worked without issues. Funny thing is I don't see what I did differently to get it to work.
Completed the tutorial successfully.
Tkank you for all the input.
Brian
The only gripe I have with the tutorial is the explanation of manipulating bits isn't clearly explained.
A bit can be set, or changed to 1, by ORing it with a 1.
Example:
Set bit 2 of an 8-bit value ---> OR with 0000-0100
result = data | 0x04;
A bit can be reset, or changed to 0, by ANDing it with 0.
Example:
Reset bit 4 of an 8-bit value ---> AND with 1110-1111
result = data & 0xEF;
Bits can also be masked out, or all the un-needed bit can be gotten rid of, by ANDing with 1.
Example:
Mask bit 3 of an 8-bit value ---> AND with 0000-1000
result = data & 0x08;
eg inverting bit 2
011 XOR with 010 yields 001
001 XOR with 010 yields 011
that being said you should look at the truth table for each operation to understand the operation
the truth table for XOR can be found here
http://en.wikipedia.org/wiki/Exclusive_or
and yes as you said " if you do an "A XOR B," it will invert every bit on A corresponding to a 1 bit on B"
A xor B
B xor A
A xor B
The value in variable A will now be in B, and value in B is now in A.
When interfacing with hardware I generally include an AND/OR and XOR around I/O operations.
The AND allows masking unwanted bits, An OR allows forcing bits on and the XOR allows polarity changes.
I do this because we all know how "tight and accurate" (sarcasm) interface specs are. So rather than having to
rework logic because of a mismatch I can correct it at the I/O point.