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.

ez430 rf3500 push button issue



w.r.t ez430-rf2500

I am trying to do something very simple here. i want to push the button, and see the LEDs light up. it is part of a complex code, but this push button is giving me some problems, someone please tell me what is my mistake. I am pasting the snippet.

 

P1OUT = 0x00; //preloading LEDs to be off

 P1DIR = 0x03; //setting LED pins to be outputs

  while(1)

  {

  if ((P1IN&0X04) == 0x00) //p1.2 is for the button. I tried the logic operation result with 0 and 1.Neither worked

  {

    P1OUT = 0X03; //if button pressed, LED on,

  }

  else

    P1OUT = 0X00; //else, LED off

  • Hi,

    I tried this problem by myself but it don't work either. But I can post my code:

    P1DIR |= 0x07; //setting LED pins to be outputs
    P1OUT |= 0x04;
      
    while(1)
    {
      if (P1IN & 0x04) //p1.2 is for the button
      {
        P1OUT &= ~0x03; //if button pressed, LED off

    }
      else  P1OUT |= 0x03;

    I declarated the button port as an Output so that the button can pull down the signal. I don't know if this is the right way but if you press the button you can detect the level change. Maybe this will help you.

    I you solved the problem, please post the solution. I am also interested

  • ok I got the soluten. You have to set P1REN for P2.1 to enable the Pullup resistor for Pin 2.1

    see my code:

    P1DIR |= 0x03; //setting LED pins to be outputs
      P1REN |= 0x04;
     
      while(1)
      {
        if (P1IN & 0x04) //p1.2 is for the button
        {
          P1OUT &= ~0x03; //if button pressed, LED on,
        }
        else  P1OUT |= 0x03;
      }

    regards

     

  • Dear Bernd: I will try that tonight, and let you know. Thanks a lot for your help!

  • Hi, I am still having problems with this button push:

    The kit I have tried with are ez430rf2500 and ez430rf2480. I can't see what the problem is. Someone please help me!

    I am obviously missing something here, please tell me what it is?

    void main()

    {

      WDTCTL = WDTPW | WDTHOLD;

      P1OUT  = 0x00; //preloading LEDs to be off

      P1DIR |= 0x03; //setting LED pins to be outputs

      P1REN |= 0x04;

      //P1OUT |=LED1ON;


      while(1)

    {

       if ((P1IN&0x04) !=0x00) //I have tried a bunch of conditional output statements, nothing works for me.

      {

        P1OUT |= (LED1ON + LED2ON) ; //if button pressed, LED's go on

      }


      else

      {

        P1OUT &=~(LED1ON + LED2ON) ; LED's off

      }

    }

    }

  • The eZ430-RF2500 as a switch between P1.2 and ground.  Therefore, you need something to pull the P1.2 node up to VDD.  Your code does now enable the internal pullup such that when the switch is not closed, P1.2 will be a logic 1.  When the switch is closed, or pushed, then P1.2 will be a logic 0.

    Your logic needs to be like the below.

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
      P1DIR |= 0x01; // Set P1.0 to output direction
      P1REN |= 0x04 ; // Enable P1.2 pullup

      while (1) // Test P1.2
      {
        if ((0x04 & P1IN) == 0x00)
          P1OUT |= 0x01; // if P1.2 set, set P1.0
        else
          P1OUT &= ~0x01; // else reset
      }
    }

  • If i have 

     if((0x04 & P1IN) == 0x00);

    Then the LEDs are always on, even when I don't push the button. Note that I am using the EZ430 RF2480 kit, although, the pin designations are the same for ez430rf2500 and ez430rf2480.

    The only difference between your code and mine is you want just one LED to come on while I want both to be on,

    let me give you my entire code from start to end:

    void main()

    {

      WDTCTL = WDTPW | WDTHOLD;

      P1OUT  = 0x00; //preloading LEDs to be off

      P1DIR |= 0x03; //setting LED pins to be outputs

      P1REN |= 0x04;

      //P1OUT |=LED1ON;

     

      while(1)

    {

       if ((P1IN&0x04)==0x00) 

      {

        P1OUT |= (LED1ON + LED2ON) ; //if button pressed, LED2 on, green

      }

     

      else

      {

        P1OUT &=~(LED1ON + LED2ON) ;

      }

    }

    }

  • I disagree, having actually tested this again on the eZ430-RF2500.  I'll conceed there may be different behavior on the eZ430-RF2480 as I have not looked at those schematics.  But for the eZ430-RF2500, the code I posted results in the following behavior.

    When the button is not pressed, the LED is off (not illuminated).
    This is due to the internal pullup on P1.2 bringing the node to a logic 1.
    In this condition, the following statement evaluates to a false condition:

    if ((0x04 & P1IN) == 0x00)

    which means the following statement is executed:

    P1OUT &= ~0x03 ;

    which drives  P1.0 and P1.1 to a logic low.  This means there is no voltage potential across the LED and it is therefore off.

     

    When I press the button, the LED is on (illuminated).

    When I release the button, the LED is off again.

     

    I modified the code to drive both LEDs as you requested.

     

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
      P1DIR |= 0x03; // Set P1.0 to output direction
      P1REN |= 0x04 ; // Enable P1.2 pullup

      while (1) // Test P1.2
      {
        if ((0x04 & P1IN) == 0x00)
          P1OUT |= 0x03; // if P1.2 set, set P1.0
        else
          P1OUT &= ~0x03; // else reset
      }
    }

    Have you tested this and get different results?

  • Its my development kit, there is something wrong with it. I need to get a new kit :( I just had it working, and now the LEDs light up when I pass the line, P1DIR |=0x03;

    Thanks though!!! I appreciate it.

**Attention** This is a public forum