This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

buttons doent work

Other Parts Discussed in Thread: MSP430F5529

hi

as i press on switch s2 (P1.1) as shown in the following code, i dont see any change in P1IN (P1IN remains constant as i press the button)

**i am using msp430f5529 lp

ps: P1DIR is input by defaulf.

#include "msp430.h"

void main()
{
WDTCTL = WDTPW + WDTHOLD; //stop watch dog timer
P1REN |= 0x02;
while(1){//do something}

}

thx :)

  • shahar asor said:
    as shown in the following code, i dont see any change in P1IN

    I can't find any P1IN access in your code :) Better rely on your code, not debugger. You would want to wite code which check P1IN bit and light LED if set. Then we continue to look what's wrong

  • hi, yes i could write a code that check the P1IN, but i chose to check it myself via the debugger instead..

    i managed to handle this issue few hours ago. apparently, the push buttons in MSP430F5529LP are working as ACTIVE LOW by default, and the P1IN is already reseted ('0') as the program begins to run. so no matter how long/fast i tried to push the buttons, P1IN never changed..

    2 ways to solve that and  use P1IN as an indicator for the buttons pressings:

    1. change the buttons to ACTIVE HIGH  by PxIES.

    or

    2. set PxOUT ('1') at the begging of the code. 

    thx :)

  • shahar asor said:
    yes i could write a code that check the P1IN, but i chose to check it myself via the debugger instead..

    I could start to guess what you are doing with (undisclosed) debugger, but I chose to stick with subject: msp430 microcontroller

  • To enable the resistor is the right way. But P1IES has nothing to do with that - you are not using interrupts in your program. P1IES just defines on which transisition, high-> low or low->high the interrupt should take effect.

    Setting P1OUT to '1' is the only way to get your program work. Setting P1OUT in combination with a pin configured as an input and enabled resistor for this pin sets the resistor as a pull-up one. If P1OUT is '0' on an input pin with enabled resistor configures the resistor to be a pull-down (default). That is why your pin always shows '0' after enabling P1REN without writing a '1' into P1OUT.

    #include "msp430.h"
    
    void main()
    {
      WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
    
    P1DIR &= ~0x02; // Setting P1.1 as an input (default) P1REN |= 0x02; // Enable a resistor on P1.1 P1OUT |= 0x02; // Setting resistor to pull-up while(1) // Do nothing { } }

  • is there any way to make the buttons work in ACTIVE HIGH mode? and if it is, is it done by using pull-down resistor?

    is there any schematic diagram that shows PIN POUT PDIR pullup/down resistors together? - that i will clearly understand what are you talking about

    thanks!

  • It depends on your hardware configuration. Are you using the launchpad? Then: No! Because you cannot change the hardwired connections on the launchpad. If you are using your own breadboard then you can place your button between Vcc and input pin and use a pull-down resistor.

    If you push your button then your input-level will change from low->high.

    You can see the configuration in the device specific datasheet of your controller. But it is a little bit complex for beginners to understand. I've added a picture of the G2553 controller's P1.3 as an example. Follow the logic to your pin on the right. You will see which bit changes operation of the pin-function.

    If you want to use your pin as an input for a push button you have to:

    Set the input pin to GPIO functionality via the PxSEL bits (GPIO is usually set per default as the device starts). Writing a '0' to those registers make them GPIOs. Depending on the used controller there are more than one (2) PxSEL bits.

    You have to set the pin to input direction via the PxDIR bits. Writing a '0' to the pin sets it to input, a '1' for output (default: input).

    Then you have to give the pin a default potential, that means it has to be high or low - never leave pins floating - the result in your register is unpredictable. If you want to use a button that shorts your pin to ground then use a pull-up if it shorts to Vcc then use a pull-down resistor. You have to options now: Use an external resistor - you do not have to configure PxREN or PxOUT in that case. Or: Use the internal ones. Via PxREN you just enable the resistor in general.

    Then you have to set the resistor for beeing a pull-down or pull-up. This is done via the PxOUT bits. Because PxOUT is '0' per default you will start with a pull-down resistor which makes no sense if your button shorts to ground. So make it a pull-up by writing a '1' to the PxOUT pin.

  • Buttons in general make or break a connection. In your case, apparently, the buttons make a connection between the pin and GND or break it. Hence the need of a resistor to VCC that is overridden by the button, when pressed.
    However, the connection to GND is hardwired by the PCB layout. The button cannot make a connection to VCC (to force the pin high) when pressed, because it is not connected to VCC.

    Changing the functionality can only be done by changing the hardware.

    Sometimes, a button is placed between two pins. So one pin can define into which direction the other one is pulled when the button is pressed. This is usually used for button matrix fields (like keyboards), to not require one pin per button. But for single pushbuttons this is seldom useful.

**Attention** This is a public forum