Jump to content
danieldlo09

Registros P1IN y P1OUT del MSP430g2152 (Registers) Help

Recommended Posts

Not so long ago i bougth the LaunchPad MSP-EXP430G2 and ordered some free samples of MSP430g2152, later when i was doing testing codes i checked that when i assign an output to the P1OUT register, the P1IN register take the same value that the P1OUT, This was odd to me, so i went to the datasheet of the msp430 family and as i was expecting the registers have two different address (P1IN 020h and P1OUT 021H), now i don't know if i have something wrong in my code or if in fact the microcontroller change both registers. Can anyone explain me what's going on or if it is normal? I'm using Code Composer Studio

 

Traducci

Share this post


Link to post
Share on other sites

Looking at the port schematic in the datasheet, you can see that PxIN.y (i.e. bit y of port x) is directly connected to the pad (via a buffer).

 

So I think by design P1IN always reflects the physical state of the pins, even for pins configured as output. However, changing the state of a pin via P1OUT is only possible when that pin is configured as output.

Share this post


Link to post
Share on other sites

P1IN will always result in a value, depending on the pin configuration this value is either the intended value on that pin or the actual value on that pin. This means that unless you have set your pin to input mode (cleared the bit in PxDIR) your PxIN will reflect PxOUT, not the actual pin value.

setting PxREN will enable pull-up/down, clearing it will disable pull-up/down; the pin is floating or driven high/low.

To set a pin to be pull-down and allow you to read the actual value you should:

  • Set the PxREN bit to 1 (enable resistor)
  • Set the PxOUT bit to 0 (pin outputs low (pull-down))
  • Set the PxDIR bit to 0 (allow PxIN to reflect the pin instead of the PxOUT value)

After this PxIN will be 1 if an external circuit pulls the pin more high (short to Vcc) than the configured pull-down resistor pulls it down.

Share this post


Link to post
Share on other sites

You're totally rigth, the tutorial says so too, maybe i didn't understand it well before because english is not my native language, but now i re-read the tutorial seeking what you're saying i realized that it is perfectly clear in the tutorial, again thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×