PIN symbol assigments on BS2p40
Zoot
Posts: 2,227
I will be using a BS2p40 for a large robot I am working on (this is my 4th or 5th robot and my second Stamp-based project).
I am getting a head start on my code, and the documentation for the BSP2p40 doesn't seem to answer how you can (or can't) assign and use PIN symbols for the two I/O groups.
On my BS2 I can do this
How would I do the equivalent on the BSP2p40? Can you do this only for the MAINIO group? Or would I do a workaround using INS, OUTS and DIRS?
Related question: is there a flag or bit or anything set by the BS2p40 that can tell you during runtime which set of I/O registers has been swapped into the main memory map? Or am I just better off setting my own bit flag in my code each time I switch I/O groups like the Manual code below?
P.S. This is my first post at the forums and I just *have* to say -- the community and support that Parallax has built is just *superb*. As are the products, of course.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
I am getting a head start on my code, and the documentation for the BSP2p40 doesn't seem to answer how you can (or can't) assign and use PIN symbols for the two I/O groups.
On my BS2 I can do this
SerOut PIN 15
How would I do the equivalent on the BSP2p40? Can you do this only for the MAINIO group? Or would I do a workaround using INS, OUTS and DIRS?
Related question: is there a flag or bit or anything set by the BS2p40 that can tell you during runtime which set of I/O registers has been swapped into the main memory map? Or am I just better off setting my own bit flag in my code each time I switch I/O groups like the Manual code below?
Stamp Manual said...
The 40-pin BS2 model has an additional set of INS, OUTS, and DIRS registers that are
switched in and out of the memory map (in place of the main INS, OUTS, and DIRS registers)
by using the AUXIO, MAINIO, and IOTERM commands.
IOTERM port ' Switch to main or aux I/Os ' -- depending on port TOGGLE 3 ' Toggle state of I/O pin 3 ' -- on main and aux, alternately port = ~port
P.S. This is my first post at the forums and I just *have* to say -- the community and support that Parallax has built is just *superb*. As are the products, of course.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
Comments
·· Attached is some BS2p40 code I am in the process of updating.· You can, however, see how the pin definitions were handled.· Basically the differentiation occurs when using the pin name.· At this point you should know which bank is currently selected.· Note: the function section of the code has been removed because it is incomplete, but you can see how things are being handled.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
What kind of amp is that you're building?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
LCD· PIN· 0
and in my aux I/O defs:
But1· PIN· 0
Then to access the LCD, then read the button·I would use:
MAINIO
SEROUT LCD, Baud, [noparse][[/noparse]"Hello!"]
AUXIO
temp = But1
So I need to switch banks before I address the given pin.· PIN definitions are similar to constants with the exception that the compiler can decide on the context of the usage and make certain changes, but it still needs to know what bank you are referring to.· I hope this helps better.· BTW, you don't need to swap banks when making the declarations, just when you refer to them later.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I am still curious, though, more as a technical point-of-fact, where does the BS2p40 keep the inactive I/O register set when it swaps 'em? I'm guessing that those locations are inaccessible via code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
·· Yes, they are inaccessable.· But they are handled by the core controller, which is an SX.· In the posted code I will actually be handling the switching between the banks within the subroutines themselves, so in my main code loop I don't have to be aware of which hardware is on which bank, although you may have noticed that the MAINIO is all inputs and the AUXIO is all outputs.· This really simplifies things.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
You can retrieve the current ioterm assignment from location 134 in the scratchpad RAM:
GET 134,mybyte
DEBUG "ioterm =", BIN1 mybyte
So, for example, you could write a subroutine that tests that flag and takes different action depending on which bank of pins is selected at entry, without having to maintain your own flag.
Locations 128 to 135 in scratchpad hold read-only information about the current state of the IO pins on both mainio and auxio. This is very useful if you get into the polling commands, especially the one that latch the state of pins for later action (POLLMODE X ' X>7). Location 127 holds the value of your current run and store banks.
I have a writeup on using POLLing at
www.emesystems.com/BS2poll.htm
and that lists functions of the read-only SP bytes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I had the SPRAM organization chart right in front of me and didn't see that. More coffee! Thanks. This is esp. helpful.
Your document on POLLing is great, btw.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
·· Sorry, I thought you wanted to be able to affect those registers without switching banks...For reading Tracy has provided that information.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com