Smarter than a P2 Smart Pin?
Steve_Hatch
Posts: 19
in Propeller 2
I have been trying to understand the smart pins on the P2. I was trying to get pins 62 and 63 to talk to the propeller output window that comes up when using flexgui. I attached the file below. I am hoping someone can help me learn what I am not seeing.
Comments
Your file is not attached.
I've included my P2 template file that uses jm_fullduplexserial.spin2 for terminal IO coms (this object uses smart pins for async io). Since you're running in FlexGUI, you'll want to change the terminal type to T_ANSI at the top of the program.
For some reason, the file that was attached was the binary file, not the text. So, I posted the full text in the next comment, hoping someone would see that the text was by the same author as the first. I used jm_fullduplexserial.spin2 as my template when designing my little program. I don't know how to change the terminal to an ANSI terminal. I still don't understand why my program won't work. What I wanted to do was use the LED's on my evaluation board to indicate what was happening until I got the program to respond to the keyboard. On the first attempt, I had P56 blinking, since I thought that using testp instruction I could read the status tof the receiver. Then when I hit any key, the blinking LED would change to P57. Then I could expand the program to shift all the bits in and read the whole character which I would send back to the terminal completing the loopback test. Instead what I am getting is both LED's taking turn randomly flashing and unable to see that a key has been pressed. It is pretty frustrating to not be able to figure out the smart pins. When they were just responding as regular IO pins it was easier to troubleshoot. The smart pins seem to hide what is going on and make troubleshooting harder. Very frustrated at the moment. Hoping to be able to figure out what is happening. My full program is an assembly level program, so I have no spin infrastructure at the top.
you need to remover the # before
Enjoy!
Mike
Yes, the # means the value gets directly encoded into the assembled instruction and acts as "immediate" data. Also called immediate addressing. Use #value or #label when the value is defined as a constant.
But when the value is stored in a variable (cog general register) then what gets encoded is the register number that holds that value. This doesn't have the #.
Well guys, thanks for your response, but that did not make it work. There is something missing that I can't see or understand, hence my statement that I am not smarter than a smart pin. This is my first experience with smart pins and so far I am not being successful.
Fixed up all the #'s ... testing it ... assembles fine ...
I sometimes have a hard time finding things on my desk because it is (clears throat)... untidy. I looked at your code and a couple of Chip's PASM-only demos and came up with this. It will echo what comes in on P63 out P62, and blip the LED on P56. If you open PST it's easy to test; what you type into the entry field is echoed to the output field
Suggestions:
-- be kind to yourself and others by formatting your code neatly
-- use Spin's built-in constants to make code easier to read and less error prone
Edit: Changed ## to # where appropriate.
Lol, took some testing but I found a real typo illusion. The pin modes for the two smartpins is set using $ when they should be %. eg: ##$0000_0000_000_0000000000000_01_11110_0 should be ##%0000_0000_000_0000000000000_01_11110_0
Amusingly, the assemblers didn't complain because the hexadecimal value was still within 32-bit bounds.
PS: As Jon mentioned, using the built-in predefines would avoid some mistakes like this.
Thank you for your help. I will have to continue to work on this. The program I am writing is going to be a compete assembler program. Once it loads it will loop within itself, so no Spin is my goal. I wrote a software UART that is working fine for me and I am going to move on without the smart pins and maybe come back to it at a later date, when I get the program working. I do appreciate your time. Without help from friends, this would be overwhelming.
Steve
Steve,
Try this. I've hacked your code around over a couple of sessions of experimenting. It's not all intentional.
Main thing is it's making use of a convenience in the assemblers where you get free assemble-time calculation and setting of the system clock frequency. Without it, specifying the components is a little messy. Also makes a reliable relationship with other frequency calculations like for baud setting.
EDIT: Updated to include reading in the byte and echoing back, like Jon did.
On the build your own assembler side of things, there is quite a lot of early hints from before the days of the predefines here - https://forums.parallax.com/discussion/169542/p2-links-for-where-to-obtain-tools-sample-test-code-reference-only/p1
and here - https://forums.parallax.com/discussion/169069/p2-tricks-traps-differences-between-p1-reference-material-only/p1
Back then, Cluso made a handy set of component constants for using to set sysclock frequency - https://forums.parallax.com/discussion/comment/1452025/#Comment_1452025
I still use that method in fact. That way I know what values the multiplier and dividers are set to when testing timings.
For a quick leg up and to keep compatibility with the constants used in Pnut/Proptool/Flexspin, Eric likely has a complete list in his sources - https://github.com/totalspectrum/spin2cpp/releases
There is no Spin in the program I uploaded yesterday. The constant expressions are evaluated by the compiler, and Spin2 constants apply to PASM2. As Evan pointed out, your code style made it tricky to spot a subtle error. To be honest, I didn't look that hard because I favor using named constants, especially when they're built into the compiler.
@evanh Are you sure you don't want that first drvl, #rxpin to be fltl?
DIRL is not DRVL. Another one of those little illusions. DIRL was more commonly used over FLTL early on and I actually prefer it for more specifically actioning the need.
That said, FLTL is fine and can save an instruction. And may be a good idea here since I do set OUT high beforehand.
Indeed. Thanks for the explanation.
FWIW Spin2 was not available when the first P2 chips became available. So initially, all code was only pasm.
Fair point, but the ability to create named constants -- which I content can be helpful to all -- has always been available.