Jump to content
43oh

msp430 development kit


Recommended Posts

i have msp430g2231 development kit. i wanted to do something with leds and buttons. my leds works fine. but somehow buttons are not.

i have limited knowledge in electronics so i could not figure out whether this is because of my code, or i need to do some arrangements in the kit itself, like something related to jumpers..

 

this is the code that i tried to run. it works when i wrote while(1). but it could not get response from the button. while(P2IN &  0X01) does not seem to work. what is wrong with this?

 

 

 

 

#include "io430.h"

void gecikme(void);

int main( void )

{

// Watchdog timer'? durdur

WDTCTL = WDTPW + WDTHOLD;

 

        P2SEL &= ~0x01;                                                                  

        P2DIR &= ~0x01;                                                             

        P2REN |= 0x01;                                                                                             

 

        P1DIR = 0xFF;

        P1OUT = 0x00;

  while(P2IN &  0X01)     {     

  for(;;)     {

   P1OUT = 0x01;

  gecikme();

  P1OUT = 0x03;

  gecikme();

  P1OUT = 0x07;

  gecikme();

  P1OUT = 0x0F;

  gecikme();

  P1OUT = 0x1F;

  gecikme();

  P1OUT = 0x3F;

  gecikme();

  P1OUT = 0x7F;

  gecikme();

  P1OUT = 0xFF;

  gecikme();

  P1OUT = 0x7F;

  gecikme();

  P1OUT = 0x3F;

  gecikme();

  P1OUT = 0x1F;

  gecikme();

  P1OUT = 0x0F;

  gecikme();

  P1OUT = 0x07;

  gecikme();

  P1OUT = 0x03;

  gecikme();

  P1OUT = 0x01;

  gecikme();

  }

 }

  return 0;

}

 

void gecikme(void){

volatile unsigned int i;

for(i=0 ; i < 50000 ; i ++);

 

}

Link to post
Share on other sites

How is your button connected?

 

As for your code, here are some notes

int maint(void) {

	//P2SEL &= ~0x01; // those 2 lines are not necessary
	//P2DIR &= ~0x01;
	P2REN |= 0x01;
        P2OUT |= 0x01; //this is necessary if your switch is connected to GND

	while (P2IN & 0X01) { // this will never execute (unless your switch is connected to Vcc and you are holding in down when starting to run,) pull resistor is set to pull-down, so P2IN & 0x01 is always false

	}

	return 0;
}
Link to post
Share on other sites

If you test the button on the PORT 2, you have to set:

P2OUT |= BIT1; //pull-up resistor
P2REN |= BIT1; //resistor enable
P2SEL &= ~BIT1; //clear
 
if you want to use interrupt:
P2IFG &= ~ BIT1; //interrupt flag - flag is zero
P2IE |= BIT1; //enable
P2IES |= BIT1; //is set with high-to-low transition
 
The datasheet for MSP430 says that after reset is P2SEL set as 0x0C0h
 
function code for MSP430F2132
Link to post
Share on other sites

 

How is your button connected?

 

As for your code, here are some notes

int maint(void) {

	//P2SEL &= ~0x01; // those 2 lines are not necessary
	//P2DIR &= ~0x01;
	P2REN |= 0x01;
        P2OUT |= 0x01; //this is necessary if your switch is connected to GND

	while (P2IN & 0X01) { // this will never execute (unless your switch is connected to Vcc and you are holding in down when starting to run,) pull resistor is set to pull-down, so P2IN & 0x01 is always false

	}

	return 0;
}

they are connected to GND.

 

 

P2REN |= 0x01;     //     These two lines sets a resistor and picks the pull down resistor option right?

P2OUT |= 0x01;   

 

then how can i control whether the button is pressed or not? what is the right while statement?

i thought these are standard lines that works for all. but obviously i was wrong.

 

 

Link to post
Share on other sites

 

If you test the button on the PORT 2, you have to set:

P2OUT |= BIT1; //pull-up resistor
P2REN |= BIT1; //resistor enable
P2SEL &= ~BIT1; //clear
 
if you want to use interrupt:
P2IFG &= ~ BIT1; //interrupt flag - flag is zero
P2IE |= BIT1; //enable
P2IES |= BIT1; //is set with high-to-low transition
 
The datasheet for MSP430 says that after reset is P2SEL set as 0x0C0h
 
function code for MSP430F2132

 

i did not use an interrupt in this particular code. i just wanted to make sure that my buttons are working.

i wrote exactly the same statements, in a different way, but does he same job. problem should not be related to those 3 lines.

Link to post
Share on other sites

P2SEL is only set for BIT6 and BIT7, so there's no need to clear it for BIT1.

Do while(1) {.....} to have infinite loop, the if() statement to detect button. Since your button is grounded, use pull up resistor, P2OUT |= 0x01;

 

 

now my code looks like this.but still button is not working. half of the leds are on whether i press or not.. why is that? did i got you wrong?

 

 

 

P2REN |= 0x01;

P2OUT |= 0x01;

P1DIR = 0xFF;

P1OUT = 0x00;

 

 

  while(1){

 

  if(P2IN & 0x01){

  P1OUT = 0xFF;

  gecikme();

  }

 

  else{

  P1OUT = 0xF0;

  gecikme();

  }

  }

  return 0;

  }

Link to post
Share on other sites

Try this:

int main( void )
{
WDTCTL = WDTPW + WDTHOLD;

P2REN |= 0x01;
P2OUT |= 0x01;
P1DIR = 0xFF;
P1OUT = 0x00;

while(1){
  if(P2IN & 0x01){
    P1OUT = 0xFF;
    gecikme();
  } else {
    P1OUT = 0x00;
    gecikme();
  }

?}
}

BTW, is your switch connected to P2.0 and GND?

tried, but did not work. i will post an image because i also dont know why p2.4 led is almost on..what is happenning in there, maybe it gives you an idea?

switch is connected o p2? well i dont know actually.  my lack of knowledge in electronics..i really appriciate the help.

 

 

 

post-37187-0-87177200-1399847356_thumb.jpg

Link to post
Share on other sites

What is the name of this board?

P2.4's brightness suggests weak pull resistor (make sure JP3 is in off position) or possible mistake in code (0x10 instead of 0x01.)

Looking at the picture, P2.0 switch is most likely SW23. Also, can you changing JP5 to off and see if the switch works?

 

EDIT: OK, I found the schematic. There are some other things connected to P2.0 but above steps should work.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...