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-RF2500 Help Thread

Hey guys,

I'm somewhat new to programming microcontrollers.  I mean I've taken a course before on programming an MSP430, but I was using a different kit then, and now I am workign with the ez430-RF2500 development kit.  I'm having a lot of trouble understanding, especially the wireless communication.  I've never dealt with wireless microcontroller programming. 

I just wanted to start this thread as a way for me (and maybe others) to find help on this particular kit. 

And please try and be patient with me, again I'm quite new so you can expect A LOT of stupid question from me on this issue.

 

As for my first question, it's a very simple one.  I've basically started developing on the kit from scratch, and I've been doing something very simple with it, like lighting LEDs and such. I'm now trying to get the button to work which I can't seem to do.  Here is a piece of my code:

#include "msp430x22x4.h"

void getBtn(void);
void LEDOn(void);
void LEDOff(void);
void LEDRed(void);
void LEDGreen(void);
void swDelay(unsigned int cnt);

int hitkey, i;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;
  while(1)
  {
    hitkey = 0;
    LEDOff();
    while (hitkey == 0)
    {
      getBtn();
    }
   
    if (hitkey != 0)
    {
      // Do stuff here
    }
  }
}

 

void getBtn(void)
{
  P1DIR &= ~(BIT2);       // Set P1.2 to input direction
  P1SEL &= ~(BIT2);          // P1.2 set to I/O option
  hitkey = P1IN & BIT2;   // AND with BIT2 to get just the value of P1.2
}

It's quite simple what I am trying to do.  Maybe at the hit of the button I light some LED's or something, but the problem is that when I push it, nothing happens.  The breakpoint never hits the next statement. Does anyone know the reason why?

The second question I have is how I can write the interrupt for the button?  It's quite primitive I understand, how I have the code written now, but I wasn't quite sure on how to write the interrupt for this.

 

Thanks in advance for your help.

  • Hi Freelancer,

    The easiest way to accomplish this is to use a GPIO interrupt driven event or function-based polling. See this file msp430x22x4_p1_02.c from our code examples for this part: http://www.ti.com/lit/zip/slac123 With this code you can toggle the LED in the interrupt service routine. If you still prefer polling P1_01 illustrates the way you poll the appropriate GPIO flag.

    Please let me know if you have any further issues.

  • Thanks for the help Brandon.

    I took function and implemented it in the following way (the button is on P1.2 instead of P1.3 right?):

    int hitkey = 0;

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;
      P1IE |= 0x04;                             // P1.2 interrupt enabled
      P1IES |= 0x04;                            // P1.2 Hi/lo edge
      P1IFG &= ~0x04;                           // P1.2 IFG cleared

      while(1)
      {   
        if (hitkey != 0)
        {
          // Do Stuff
        }
      __bis_SR_register(LPM4_bits + GIE);       // Enter LPM4 w/interrupt
      }
    }

     

    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
      hitkey ^= 0x01;
      P1IFG &= ~0x04;                           // P1.2 IFG cleared
    }

    I set a breakpoint within the interrupt, but it never hits there. Is there something I'm doing wrong?

  • Hi Freelancer,

    here is a bit of code that works with the push button on the RF2500 Target board.

    You will have to press in the middle of the push button, as the push is not always recognized.

    Also, pay attention to the debouncing for-loop which is missing in your code - you may try adding that one first.

    Also the interrupt function name has the _ISR extension, not sure if this mandatory or not, though.

    /*------------------------------------------------------------------------------
    * Push BUTTON on RF2500 Target Board ISR
    ------------------------------------------------------------------------------*/
    #pragma vector=PORT1_VECTOR
    __interrupt void Port1_Button_ISR (void)

      for(unsigned int i=0; i<=2000;i++);
      P1IFG &= ~BIT2;
      button_pushed = 1;   
      __bic_SR_register_on_exit(LPM3_bits);        // Clear LPM3 bit from 0(SR)
    }

    In your main() you should have this:

    *****

        if (button_pushed) { //Flag is set by Push Button ISR
            //BSP_TOGGLE_LED2(); if you like
          //do your stuff here
           button_pushed = 0;

    }

    The example is based on the Wireless sensor monitor (the default SW with the kit).

    Let me know if it works for you!

    Br,

    Odessos

  • Hi Odessos,

    this is my code about how to use pushbutton to triggle LED. I use RF2500, I don't know why.

    I have the same problem.

    why I cannot let pushbutton work. here is my code.

    int main( void )
    {
      // Stop watchdog timer to prevent time out reset
      WDTCTL = WDTPW + WDTHOLD;
     
      P1DIR |= 0x01; // P1.0 output 
     
      P1IE |= 0x04;                             // P1.2 interrupt enabled
      P1IES |= 0x04;                            // P1.2 Hi/lo edge
      P1IFG &= ~0x04;   
      __bis_SR_register(LPM4_bits + GIE); 

    }

    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
      P1OUT ^= 0x01;                            // P1.0 = toggle
      P1IFG &= ~0x04;                           // P1.2 IFG cleared
    }

     

    Thank you for your help

     

     

  • Hi Odessos,

    I gave that a shot, but unfortunately that didn't work either.  I can't imagine what I did wrong before in my code, and what I'm doing wrong right now.  Do you think that you could paste your complete code for that one file that you are using?  Maybe there is something in the headers that I haevn't set right.  Here is my complete code with your suggestions used.  If you could take a look at it that would be great.

     

    /******************************************************************************

    Title: testthing.c
    Author: Freelancer
    Date Created: Aug 28, 2008

    Description:
    A test program written to play around with the EZ430 Development Kit.

    *******************************************************************************/

    #include "msp430x22x4.h"

    void getBtn(void);
    void LEDOn(void);
    void LEDOff(void);
    void LEDRed(void);
    void LEDGreen(void);
    void swDelay(unsigned int cnt);
    //__interrupt void Port_1();

    int hitkey = 0;

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;
      //GIE;
      P1IE |= 0x04;                             // P1.2 interrupt enabled
      P1IES |= 0x04;                            // P1.2 Hi/lo edge
      P1IFG &= ~0x04;                           // P1.2 IFG cleared

      while(1)
      {
        //hitkey = 0;
        //LEDOff();   
        if (hitkey != 0)
        {
          LEDRed(); swDelay(1); LEDOff(); swDelay(1);
          LEDGreen(); swDelay(1); LEDOff(); swDelay(1);
          LEDOn(); swDelay(1); LEDOff(); swDelay(1);
        }
      //__bis_SR_register(LPM4_bits + GIE);       // Enter LPM4 w/interrupt
      }
    }



    // |***************************************************************************|
    // |                                                                           |
    // |               F U N C T I O N   D E F I N I T I O N S                     |
    // |                                                                           |
    // |***************************************************************************|


    void getBtn(void)
    {
      P1DIR &= ~(BIT2);       // Set P1.2 to input direction
      P1SEL &= ~(BIT2);          // P1.2 set to I/O option
      hitkey = P1IN & BIT2;   // AND with BIT2 to get just the value of P1.2
    }

    void LEDOn(void)
    {
      P1DIR |= (BIT1|BIT0);   // Set P1.1-1.0 to output direction
      P1SEL &= ~(BIT1|BIT0);  // P1.1-1.0 I/O option
      P1OUT |= (BIT1|BIT0);   // P1.1-1.0 output = 1, LED ON
    }

    void LEDOff(void)
    {
      P1DIR |= (BIT1|BIT0);   // Set P1.1-1.0 to output direction
      P1SEL &= ~(BIT1|BIT0);  // P1.1-1.0 I/O option 
      P1OUT &= ~(BIT1|BIT0);  // LED Off
    }

    void LEDRed(void)
    {
      P1DIR |= (BIT1|BIT0);   // Set P1.1-1.0 to output direction
      P1SEL &= (BIT1|BIT0);   // P1.1-1.0 I/O option
      P1OUT &= ~(BIT1|BIT0);  // Clear LED ports
      P1OUT |= (BIT0);        // P1.0 On
    }

    void LEDGreen(void)
    {
      P1DIR |= (BIT1|BIT0);   // Set P1.1-1.0 to output direction
      P1SEL &= (BIT1|BIT0);   // P1.1-1.0 I/O option 
      P1OUT &= ~(BIT1|BIT0);  // Clear LED ports
      P1OUT |= (BIT1);        // P1.1 On
    }

    void swDelay(unsigned int cnt)
    {
      int i, i2 = 0;
      while (i2 <= cnt)
      {
        for(i = 0; i < 0xFFFF; i++){}
        i2++;
      }
    }

    /*
    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port1_Button_ISR(void)
    {
      //P1OUT ^= 0x01;                            // P1.0 = toggle
      hitkey ^= 0x01;
      P1IFG &= ~0x04;                           // P1.3 IFG cleared
    }
    */

    #pragma vector=PORT1_VECTOR
    __interrupt void Port1_Button_ISR (void)
    {
      for(unsigned int i=0; i<=2000;i++);
      P1IFG &= ~BIT2;
      hitkey = 1;  
      __bic_SR_register_on_exit(LPM3_bits);        // Clear LPM3 bit from 0(SR)
    }

     

     

  • Freelancer said:
    how I can write the interrupt for the button

    The button on the eZ430-RF2500 is on P1.2 and takes advantage of the MSP430's internal pullups.  By default, the pull up is disabled and the button will not do anything unless this is configured.  This is why all the code above doesn't work.  The key line everyone is missing is "P1REN |= 0x04;".

    I've attached a code example that uses the button to cycle through the LEDs which you can import into your project (rename to *.c.  The forum doesn't allow posting *.c files for some reason.)

    or you can cut & paste the following:

    //******************************************************************************
    // Enable the button on the eZ430-RF2500 (P1.2) using the internal pull-up to
    // cycles between the LEDs.
    //
    //               MSP430F22x4
    //            -----------------
    //        /|\|                 |
    //         | |                 |
    //         --|RST              |
    //           |             P1.1|-->LED
    //      --o--|P1.2         P1.0|-->LED
    //     \|/
    //
    //  A. Valenzuela
    //  Texas Instruments Inc.
    //  May 2007
    //******************************************************************************
    #include "msp430x22x4.h"

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO
      IFG1 &= ~OFIFG;                           // Clear OSCFault flag
      __bis_SR_register(SCG1 + SCG0);           // Stop DCO
      BCSCTL2 |= SELM_3 + DIVM_3;               // MCLK = LFXT1/8

      P1DIR |= 0x03;                            // Set P1.0, P1.1 to output
      P1OUT &= ~0x3;                             //P1.0, P1.1 low
      P1IE |= 0x04;                             // P1.2 interrupt enabled
      P1IES |= 0x04;                            // P1.2 Hi/lo edge
      P1IFG &= ~0x04;                           // P1.2 IFG cleared
      P1REN |= 0x04;                            // P1.2 pullup
      P1OUT |= 0x04;                            // P1.2 pullup

      __bis_SR_register(LPM3_bits + GIE);       // Enter LPM4 w/interrupt
    }

    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
      while(!P1IN&0x04);                        // Wait for button debounce
                                                // remove while() if delay_cyles used
      P1OUT++;                                  // Cycle LEDs
      P1OUT &= 0x03;                            // LED Circular Buffer
      P1OUT |= 0x04;                            // P1.2 pullup
      P1IFG &= ~0x04;                           // P1.2 IFG cleared
      //__delay_cycles(500);                      // Button delay (IAR & CCE v3.1+)
    }

     

  • I have posted similar question in another thread ( wrong thread): how do I get  temperature and humidity sensors built  like the demo ( zigbee demo msp 430 -cc 2480)in a production mode, what is the price?

     

    best regards,

    Debebe Asefa

  • I was having similar problems with the push button sample code and then I found this post. Thanks a lot to the guys asking for help and big thanks to adrian for posting the solution. This was awesome help!

    It would be nice if the next rev of SLAC123 code examples for 22x2 and 22x4 would be fixed to use the correct pin for the push button and add the missing P1REN line.

  • Adrian,

             Confirmed that the code works. Could you explain how this line does the debouncing?

    while(!P1IN&0x03);                        // Wait for button debounce

    the pushbutton is on P1.2 and you are applying a '0' to that bit thereby ignoring it. What does this line really do?

    Thanks

  • Perl Smith said:
    while(!P1IN&0x03);                        // Wait for button debounce

    looks like that line is actually a typo.  it should have been halting program execution until P1.2 is released.  i've edited my original post to be accurate.  thanks for catching that!

    the __delay_cycles line that is commented out is more effective at keeping multiple ISR from rapidly going off as you push the button.  it left it commented out because not all compilers have this intrinsic available.

  • Adrian,

            I don't see an update in your code. Are you sure you updated it?

  • Perl Smith said:
      I don't see an update in your code. Are you sure you updated it?

    yeah, i'm sure.

  • Hello,

                    Could someone explain why these lines are necessary in the above program?

    BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO (12kHz)

    IFG1 &= ~OFIFG; // Clear OSCFault flag

    __bis_SR_register(SCG1 + SCG0); // Stop DCO

    BCSCTL2 |= SELM_3 + DIVM_3; // MCLK = LFXT1/8 (1.5kHz)

    Thanks

**Attention** This is a public forum