How do you set Pullup/Pulldown?
iseries
Posts: 1,492
in Propeller 2
I can't make heads or tails out of the documentation. I would think setting this is simple enough.
On STM products there is a separate register just for pullup/pulldown that you set for each GPIO pin. One and done.
It looks like on the P2 I have to find the correct bit position or something or enable smart pin.
Searching the documentation for Pullup reveals nothing.
Think I have to use the WRPIN instruction and figure out what "D/# = %AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0" means.
All I can make out is there is a lot of P.
Mike
On STM products there is a separate register just for pullup/pulldown that you set for each GPIO pin. One and done.
It looks like on the P2 I have to find the correct bit position or something or enable smart pin.
Searching the documentation for Pullup reveals nothing.
Think I have to use the WRPIN instruction and figure out what "D/# = %AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0" means.
All I can make out is there is a lot of P.
Mike
Comments
If you want to add a pull-up
Pull-down:
PASM:
I'm writing in C so I need to bit bang it.
Mike
https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/edit#heading=h.1h0sz9w9bl25
A input selector = 0 (true)
B input selector = 0 (true)
AB input logic = 0
Pin A logic input = 1, C = 0 (live), I = 0 (not inverted), 0 = 0 (not inverted output), H = 1, (1.5k high), L = 7 (float), T = 0, M = 0 (smart pin off).
0b00000000000000100000111100000000
Mike
Edit: Per Ray's comment (below) -- if you're using FlexC -- you can do this:
That said, you should probably reach out to your compiler vendor for confirmation.
Suggestion: Since you're using C which is not the native language of the Propeller, you may want to include the language and compiler you're using in the thread header so that people who do know that product can assist. Not everybody reads every thread, but I know guys like Eric and Ross are very good at supporting the people using their compilers.
But, I think FlexSpin now has all the Spin2 constants for these things.
So, you could probably replace the "0b001000 << 8" with some constant from the Spin2 docs...
BTW: Pullups and pulldowns are strange on P2... The resistors are sorta between the high or low voltage and the pin. So, in order for the above to work you need to drive the pins high too.
And if you know this it is also clear that you have to set the pin as output to activate the pullup or pulldown resistor. Of course you can still use the same pin as input.
That makes a lot of sense.
I think I'll stick with a resistor to 3.3v. It's simpler.
Mike
For inputs you can safely use the internal pullups or pulldowns. They don't cost money nor board space and adding a line or two to the code is faster than using the soldering iron. And the state of the pin doesn't matter until you are ready to read it.
In TAQOZ to use a 1k5 pullup and CMOS sink on both I2C pins I can specify it like this:
The 56 2 PINS sets the pin range to operate on plus it also clears the pinmode variable then 1K5 PULLUP sets the appropriate bits in that variable as does CMOS SINK and so SETPIN writes that to the selected pins.
Thought I would try some I2c code on prop2. Jon has indicated that P_HIGH_1K5 and other constants have been defined for doing this and used with wrpin() and indeed work in flexbasic. (nice one Eric)
BUT- how did you find this information? I have looked at every document I could find on the website, done searches but to no avail. Only by looking at other peoples code do I find examples. I feel like I am pecking around trying to pick up crumbs of information from other peoples code. Its time consuming, irritating and only covers that particular situation- other options are hard to find. Can someone point to easily understood documentation on the subject please.
WAIT!- Just found about 10 posts earlier in this thread Jon posted-
OK, that's great! BUT I'm not a spin programmer, nevertheless its very useful.
I guess its hidden away in Chips P2 google document- but I've crawled painfully through it and couldn't find it and trying to search on the document doesn't work.
The P2 is great but fathoming it out is not.
I guess I just have to be patient until someone writes an "idiots guide to the prop2"
(didn't have this problem with the prop1 but then I was late on the scene- and it is a LOT simpler)
Dave
I guess I'm in the same boat. Came late to the P1 which was great since all the C stuff was well on it's way.
Now with the P2 it's all about SPIN right now. Thankfully Eric has done a great job at getting C going.
Google docs are good and I have them bookmarked for easy reference.
Download the propeller tool just to get more documentation.
Mike
The pullups are part of the Smart Pin... The table in the docs (see below) shows how to set them.
I guess it doesn't help that they are labelled here as M bits for some reason when described earlier as P bits...
Right, I was trying to read that table but it is in blue and very small and confusing. It has a column with Pin A out but then it talks about input? Then there is HHH and LLL which I assume mean Pull High or Pull Low.
Then there is Fast and Float? Is Fast a dead short?
Mike
Well yes- but that's not all there is- this is a snip from the spin document Jon referred me to-
much more readable.
Dave
I don't know what documentation you have for the compiler you're using, but it seems that those constants should be listed there, too.
Fast is direct output from the pin driver. Float is the disconnecting the pin driver (e.g., when using an external pull-up/pull-down)
I use FlexProp for my C programming which is working well. No documentation about the P2 other than the basic functions.
Have to refer to the SPIN documents or Google documents in general.
Mike
dgately
Based on the instruction set of the P2 it's going to take some time to document them.
Mike