Jump to content
43oh

Recommended Posts

I'm new to Microcontrollers and the Launchpad and I'm trying to implement simple programs that receive and send input and output from OUTSIDE the Launchpad, but I'm having trouble doing so. Currently, I'm testing receiving input by making the onboard red LED turn on when the microcontroller receives input on a specified pin (in this case, P1.5). But with both the microntrollers that come with the Launchpad (MSP430G2231 and MSP430G2211), whenever I wire an input to P1.5 the red LED turns on, even touching a wire to the pin without power to it turns on the LED. The code I have written works when taking input on P1.3 (Onboard Switch 2) and is responsive, but not on P1.5. Sometimes the red LED is initially on and stays on. I have looked at circuit diagrams of taking input from sources other than onboard switches, but I'm not completely sure on how to wire my circuits to the board. So I have a couple questions:

 

How do you properly wire off-board inputs and outputs with an external 3V power source?

What is proper and efficient code for detecting input?

And is it possible the Launchpad or the Microcontrollers are faulty?

 

Code:

#include 

#define OUPUT_1 BIT4 // output on P1.4
#define OUTPUT_0 BIT0 //Red LED
#define SENSOR_1 BIT5

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stops watchdog timer

P1DIR &= ~SENSOR_1;
P1DIR |= OUTPUT_0;
P1OUT = 0;

while(1)
{
	if((P1IN & SENSOR_1) != 0){
		P1OUT &= ~(OUTPUT_0);
	}
	else
	{
		P1OUT |= OUTPUT_0;
	}
}
}

Link to post
Share on other sites

Have you tried using the built in resistors to pull up or pull down the pin? (P1REN) Your pin may be floating and could cause some weird issues. And no your chip is not likely faulty.

 

 

 

and try this code example from TI

 

//******************************************************************************
//  MSP430F20xx Demo - Poll P1 With Software with Internal Pull-up

//  M. Buccini / L. Westlund
//  Texas Instruments Inc.
//  September 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
//******************************************************************************

#include  

void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
 P1DIR = 0x01;                             // P1.0 output, else input
 P1OUT = 0x10;                             // P1.4 set, else reset
 P1REN |= 0x10;                            // P1.4 pullup

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

 

the best and most efficient way to detect inputs is probably using the ISR for that port, but it all depends on you and what you are trying to do. you are on the right track for SW polling which is fine if you dont need to act on that event right away.

Link to post
Share on other sites

I should've mentioned before, when first experimenting with the board, I reinserted the microcontroller backwards and powered it up, could it have damaged the board? :? The microcontroller can still be programmed and operation seems normal, I just can't get off-board peripherals to work. Is there anyway I could check if the board is damaged and I should just order another?

 

Applying the pull-up resistor part to my code, when touching a wire to the pin hole, the Red LED flickers on then off quickly. It's a start but I probably need to solder a female header onto the board to get a good connection. But still, even a wire with no power can set it off, is that normal?

Link to post
Share on other sites
I should've mentioned before, when first experimenting with the board, I reinserted the microcontroller backwards and powered it up, could it have damaged the board? :? The microcontroller can still be programmed and operation seems normal, I just can't get off-board peripherals to work. Is there anyway I could check if the board is damaged and I should just order another?

 

:o :shock:

 

I doubt the board is damaged but I would say that micro is toast. You can't trust it to operate properly after that.

 

The best way to see if that micro is toast is to program it to go into low power mode 4 and measure the current consumption. If it's above 1 milliamp then you know it's fried.

 

I've damaged a G2231 by pulling an I/O pin to 5 volts. The output protection diode was roasted and the micro constantly consumed 30mA. I just threw away that micro.

 

You shouldn't trust that micro anymore.

 

Go to TI and ask for a free sample or two of that part. It will make you feel better knowing that they'll send you some for free :D

Link to post
Share on other sites

Go to TI and ask for a free sample or two of that part. It will make you feel better knowing that they'll send you some for free :D

 

Indeed. They seem to be very generous with free samples as long as the person doesn't try to exploit their sample program. If you live in the USA, it will probably arrive within about 2-3 days (they are very fast).

 

It might also be a good idea to buy a few extra Launchpads just to simply have them on-hand. You might find that you want to mod a few of them, or install the headers on a board for Booster Packs but leave them off of another board. Or install the external crystal. Or ultimately use them in a permanent enclosure. At $4.30, I think that they are a heck of a platform. The emulators alone are awesome, considering that you can use them to program practically any chip in the lineup.

Link to post
Share on other sites
Indeed. They seem to be very generous with free samples as long as the person doesn't try to exploit their sample program. If you live in the USA, it will probably arrive within about 2-3 days (they are very fast).

They arrive to the Far Side of Nowhere on the third day. What's taking them so long domestically?! :lol:

Link to post
Share on other sites

I got off-board input and output working, and as far as I can see, the chips as well as the board are not fried due to my stroke of stupidity! :roll: I also ordered some samples from TI for other microcontrollers and I look forward to further experimentation with the Launchpad. Thanks for your support guys.

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...