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.

CCS/MSP430G2553: CCS/MSP430G2553

Part Number: MSP430G2553

Tool/software: Code Composer Studio

#include <msp430.h> 
#define MA1 BIT0
#define MA2 BIT1
#define MB1 BIT2
#define MB2 BIT4

int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
	 P2DIR &= ~BIT1 + BIT2 + BIT3 + BIT4 ; //explicitly making P2 as Input - even though by default its Input
	 P2REN |= BIT1 + BIT2 + BIT3 + BIT4; //Enable Pullup/down
	 P2OUT |= BIT1 + BIT2 + BIT3 + BIT4; //Select Pulldown

	 P1DIR |= MA1 + MA2 + MB1 + MB2;

	         while(1)
	         {
	           if(!(P2IN & BIT1)) // forward
	           {
	               P1OUT |= MA1 + MB1;
	               P1OUT &= ~MA2 + MB2;
	               __delay_cycles(500);

	           }
	           if (!(P2IN & BIT2)) // REVERSE
	           {
	               P1OUT |= MB2;
	               P1OUT |= MA2;
	               P1OUT &= ~MA1 + MB1;
	               __delay_cycles(500);

	           }
	           if (!(P2IN & BIT3)) // RIGHT
	           {
	               P1OUT |= MA1;
	               P1OUT &= ~MA2 + MB1;
	               P1OUT &= ~MB2;
	               __delay_cycles(500);

	           }
	           if (!(P2IN & BIT4)) // LEFT
	           {
	               P1OUT |= MB2;
	               P1OUT &= ~MA1 + MA2;
	               P1OUT &= ~MB1;
	               __delay_cycles(500);

	           }
	           else
	           {
	               P1OUT = 0x00;
	               __delay_cycles(500);

	           }
	         }
	//return 0;
}

This is my code my using this for motor controller

but its not working properly.

MB2 is not working it provides only 0.2v at output when it is on. while other 2.1v

i tried many thing but its power priblem remains constant.

please give me a proper solution

Thanking you.

  • i tried it with both pullup and pulldown mode too by changing registers but its remain constant
  • Please correct the "If The Else" and the inverted bits in bracket:

    #include <msp430.h>
    #define MA1 BIT0
    #define MA2 BIT1
    #define MB1 BIT2
    #define MB2 BIT4
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
         P2DIR &= ~(BIT1 + BIT2 + BIT3 + BIT4) ; //explicitly making P2 as Input - even though by default its Input
         P2REN |= BIT1 + BIT2 + BIT3 + BIT4; //Enable Pullup/down
         P2OUT |= BIT1 + BIT2 + BIT3 + BIT4; //Select Pulldown
         P1DIR |= MA1 + MA2 + MB1 + MB2;
                 while(1)
                 {
                   if(!(P2IN & BIT1)) // forward
                   {
                       P1OUT |= MA1 + MB1;
                       P1OUT &= ~(MA2 + MB2);
                       __delay_cycles(500);
                   }
                   else
                   if (!(P2IN & BIT2)) // REVERSE
                   {
                       P1OUT |= MB2;
                       P1OUT |= MA2;
                       P1OUT &= ~(MA1 + MB1);
                       __delay_cycles(500);
                   }
                   else
                   
    if (!(P2IN & BIT3)) // RIGHT
                   {
                       P1OUT |= MA1;
                       P1OUT &= ~(MA2 + MB1);
                       P1OUT &= ~MB2;
                       __delay_cycles(500);
                   }
                   else
                   
    if (!(P2IN & BIT4)) // LEFT
                   {
                       P1OUT |= MB2;
                       P1OUT &= ~(MA1 + MA2);
                       P1OUT &= ~MB1;
                       __delay_cycles(500);
                   }
                   else
                   {
                       P1OUT = 0x00;
                       __delay_cycles(500);
                   }
                 }
        //return 0;
    }
  • > P2DIR &= ~BIT1 + BIT2 + BIT3 + BIT4 ; //explicitly making P2 as Input - even though by default its Input
    This doesn't do what you think it does. Since the subsequent code suggests you want all of P2.1-P2.4 to be inputs, try:
    > P2DIR &= ~(BIT1 + BIT2 + BIT3 + BIT4) ; // P2.1-P2.4 Input - even though by default they're Input
    ------
    > P1OUT &= ~MA1 + MA2;
    This has a similar problem, but here I think you're trying to set MA1 low and MA2 high, so you should split them:
    > P1OUT &= ~MA1;
    > P1OUT |= MA2;

    I count 4x instances of this.

    [Edit: Added note about multiple instances.]

  • I think there should have a power problem.
    is it possible???
  • [I've added a note above about multiple instances of Part 2 of my suggestions.]

    The symptom you described on MB2 suggests a bus conflict, so I suppose it's possible something got damaged by the earlier code, but I've found MSP430s to be pretty tough. There also might be a wiring error somewhere, but we can't see that from here.

    That said: If the symptom persists after fixing the code, you could try swapping for a new Launchpad.
  • > P1OUT &= ~MA1 + MA2;

    for i want to keep both low

  • this resolve my problem

    Thank u sir

**Attention** This is a public forum