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.
To be honest, I am stuck in figuring out how to use the P1.3 button.
I have MSP430G2553 just like you and allover the web people are talking about pullup resistors and other b-s.
How should I use this button using my MCU? There is absolutely 0 help online on this topic..
Please help me, would love it if you'd include a code sample..
Thanks in advance from me and from all the other noobs out there ;-)
There are some things you cannot do in software. If you want to only do software, a microcontroller definitely isn't your best target. Else you should try to understand what this means and why people are talking about this.Arcady Trembovler said:allover the web people are talking about pullup resistors and other b-s.
instead of mocking me, please take a look at this:
#include "msp430g2553.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= 0x01; // Set P1.0 to output direction P1IE |= 0x08; // P1.3 interrupt enabled P1IFG &= ~0x08; // P1.3 IFG cleared _BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1OUT ^= 0x01; // P1.0 = toggle P1IFG &= ~0x08; // P1.3 IFG cleared } |
why isn't it working for me?
Thanks a bunch!
Now it works really okay:
#include "msp430g2553.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT |= 8;
P1REN |= 8;
P1DIR |= 0x01; // Set P1.0 to output direction
P1IE |= 0x08; // P1.3 interrupt enabled
P1IFG &= ~0x08; // P1.3 IFG cleared
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
//for(;;); //loop is unnecessary..
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= 0x01; // P1.0 = toggle
P1IFG &= ~0x08; // P1.3 IFG cleared
}
As far as I can tell JMG wasn't trying to mock you, Arcady. The code that OCY gave you enables the internal pull up resistor on the 4th pin, since an input by default "floats" with unpredictable logic level, hence it will not detect the button press (i.e. a high-low edge transition through pulling down the input pin to ground/logic 0).
I agree that the details may seem unclear or non-obvious to a "newbie", but things like logic levels, edge transitions, and pulling up/down are fundamental to digital electronics. The exact implementation and mechanics may vary, but the principles are universal.
Tony
As Tony already wrote, my intention wasn't to mock you but to tell you that you already got the answer - and declared it for b-s.Arcady Trembovler said:instead of mocking me
Microcontroller programming is not only software but also hardware. If you don't want to take care of hardware requirements, you won't get far.
A pushbutton is not a device with OS-provided API. It is a simple switch that connects a hardware port pin to GND signal level. And when you release it, the port pin will still be on GND level if there is nothing 'pulling it up' again. These are the pullups the people were talking about.
You got the solution, but you didn't understand it and even didn't try to understand it and instead of asking for an explanation, you asked for a solution that you like better. That's the way managers operate, not engineers. And definitely the wrong approach in the microcontroller world.
However, you already got a code fix posted above. But I guess you still do not understand why it was needed and how it works. And even though your program now may work as intended, it most likely hasn't helped you a single bit towards your first own project. And you'll likely need the same kind of help for the next component you want to use - a waste of our time and yours.
JMC,
I am with you deep in my heart. And I admire what you did.
But, observing the current trend here and elsewhere, I became very cynical. Most people do not want to know why or how. All they care about is “send me the c code”. I gave up on being Man of La Mancha.
--OCY
First, fellas, big thanks to everybody..
If you, JMC, would be so informative in the beginning, I would be very greatful. You told me to "go study" when there is nowhere to study from!
You spotted me right-on... I study computer science, not electronics, and that's why I decided to begin with the Launchpad, so I guess this is the reason why this "transformation" is not very intuitive for me.
There are no books about MSP430G2 Launchpad, and the only thing I got in this world is this forum (and other forums which aren't any different, so all I can do is learn from examples). If I could read it out somewhere I would. Maybe I don't know where to look, so if you have few favorite books/sites to recommend I'd gladly check them out.
I noticed that the code used for MSP430G2231 isn't working on my MSP430G2553 and I had no idea why; Yes, people mentioned pull-up resistors but never bothered explaining..
I hope you understand my point of view on things and where I am coming from - I wouldn't mind reading some theory - problem is - I don't know what to read!
If you have any books to recommend - I'd be glad to check them out!
Thanks again!
Hi Arcady,
I remember stumbling upon "MSP430 Microcontroller Basics" by John H. Davie, which was written by the author to be used as the second half of a digital electronics course; from my brief skimming the book looked very well written so you may want to check it out.
There is also the free "MSP430 Teaching ROM" by Texas Instruments which is meant for use in a university course.
As for more general information on digital electronics, there's a plethora of resources available on the 'Net, just google for "digital logic", "digital circuits", and the like.
Hope this helps. Happy learning!
Tony
A google search for 'pullup resistor' links to wikipedia with the very first hit. It gives a fairly complete description of what pullup resistors are and why they are needed and how they are used. Including lots of links explaining the different electronic parts.Arcady Trembovler said:If I could read it out somewhere I would
he only MSP-(and therefore LaunchPad-)related information regarding this issue is that most newer MSPs, including the G2 series, have internal pullup resistors that can be activated by software. This info is in the digital I/O chapter of the 2x family users guide that should be read by everyone whoo uses a 2xx family device including the G2. It can be downloaded form the LaunchPad product page, along with the device datasheet for the processors. And that earlier versions of the LaunchPad did have an external pullup-resistor soldered at the pushbutton, which has been removed on newer revisions to allow analog usage of teh pin (if the button isn't pressed, it is electrically invisible. The pullup, however, did influence analog signals)
My own book about the MSP processors is far from being complete and not released yet.(and at the current pace, I doubt I'll ever finish it) But it won't cover basics of electronic circuitry too. Except a few things that are less commonly known by 'normal' electronic engineers but are important for the MSP.
**Attention** This is a public forum