2 buttons useable?

301 views
Skip to first unread message

Kevin Mark

unread,
Oct 11, 2010, 9:53:17 AM10/11/10
to ti-lau...@googlegroups.com
I have seen code that allows you to use SW2 on the launchpad for input but I
have not been able to use SW1.
am I missing something other than it seems to be used to reset the program?
--
| .''`. == Debian GNU/Linux ==.| http://kevix.myopenid.com......|
| : :' : The Universal OS....| mysite.verizon.net/kevin.mark/.|
| `. `' http://www.debian.org/.| http://counter.li.org [#238656]|
|___`-____Unless I ask to be CCd,.assume I am subscribed._________|

T_Shirt

unread,
Oct 11, 2010, 1:22:38 PM10/11/10
to TI Launchpad
I believe it is wired straight to the Reset Pin which makes it kinda
limited for input use.
You can hook up switches that you supply for the other pins of course.

gatesphere

unread,
Oct 11, 2010, 1:54:09 PM10/11/10
to ti-lau...@googlegroups.com
T_Shirt is correct, it is wired directly to the RST pin. And, as TI
didn't provide jumpers to disconnect the two switches like they did for
the two LEDs, you can't really repurpose it either. But, a reset switch
is a very handy thing to have, and I'm glad TI included it. I just wish
it was jumpered like the LEDs.
-->gatesphere/suspended-chord

Old_Cow_Yellow

unread,
Oct 11, 2010, 2:43:53 PM10/11/10
to TI Launchpad
Actually, you could. But it is a little tricky.

Your firmware could setup the RSTn/NMI pin in the NMI mode to trigger
an interrupt at either the rising or falling edge. The enable bit and
edge select bit are in the WDTCTL register.

This is kind of nice because in addition to the 10 GPIO pins, you have
gained an additional input pin and on the LaunchPad, that pin is
already wired to a push-button with pull-up resistor. So out of a 14-
pin chip, you have 11 I/O pins. Not bad at all!

-- OCY

gatesphere

unread,
Oct 11, 2010, 4:09:58 PM10/11/10
to ti-lau...@googlegroups.com
Thanks for the info, OCY! I was unaware of that trick.
-->gatesphere/suspended-chord

Kevin Mark

unread,
Oct 12, 2010, 2:14:58 AM10/12/10
to ti-lau...@googlegroups.com
On Mon, Oct 11, 2010 at 11:43:53AM -0700, Old_Cow_Yellow wrote:
> Actually, you could. But it is a little tricky.
>
> Your firmware could setup the RSTn/NMI pin in the NMI mode to trigger
> an interrupt at either the rising or falling edge. The enable bit and
> edge select bit are in the WDTCTL register.
>
> This is kind of nice because in addition to the 10 GPIO pins, you have
> gained an additional input pin and on the LaunchPad, that pin is
> already wired to a push-button with pull-up resistor. So out of a 14-
> pin chip, you have 11 I/O pins. Not bad at all!
>
> -- OCY
for the newbies like me, could you write a small program to allow you to blink
LED1(P1.0)with the S1(reset)?

Christian Brugger

unread,
Oct 12, 2010, 4:55:04 AM10/12/10
to ti-lau...@googlegroups.com
Hi,

I think most of us would prefer helping you getting started, instead
of providing finished code.

As a community we don't want you to just copy&paste our code, we want
to help you learning to understand microcontrollers.

Some tutorials, you might have a look at:

- Using buttons to let LEDs blink:
--> basic: http://mspsci.blogspot.com/2010/07/tutorial-07-pushing-buttons.html
--> using interrupts:
http://www.msp430launchpad.com/search?updated-max=2010-07-30T04:22:00-04:00&max-results=7

- Setting up peripherals:
--> http://mspsci.blogspot.com/2010/07/tutorial-02-msp430-township-and.html

If you wan't to reuse the Reset-Pin, you should have a look at the
PxSEL register in the user manual for a general explanation:
--> http://focus.ti.com/lit/ug/slau144e/slau144e.pdf

And then at the datasheet of you specific chip, if you wan't to know
what the different PxSEL flags mean for the different inputs.
--> http://focus.ti.com/lit/ds/symlink/msp430g2231.pdf


Yeah you have to learn a lot at the beginning, but on the other hand,
what is it worth to rely on other's people code, you can copy&paste?

Christian

WS3Z

unread,
Oct 12, 2010, 7:24:34 AM10/12/10
to ti-lau...@googlegroups.com
All you C++ programmers say that. Too lazy to write your own code, ect.
I learn much better from code examples that I can load up and play with,
It might take a beginner to C++ a month to get the syntax correct and by
then it would be thrown out the window.

If OYC says its tricky then its not something for a beginner.
Just my 2 cents on learning code.

Old_Cow_Yellow

unread,
Oct 12, 2010, 5:37:50 PM10/12/10
to TI Launchpad
Unlike GPIO pins, the RSTn/NMI pin function is not controlled by any
PnSEL, PnIE, or PnIES registear. It is controlled by 2 of the WDTCTL
bits.

Unlike GPIO pins, you cannot read RSTn/NMI pin input level. You can
only set it up to generate an NMI interrupt at either the rising or
falling edge of RSTn/NMI pin.

Unlike maskable interrupts, NMI interrupt cannot be masked by GIE. As
a result, it may even interrupt ISR of maskable interrupts.

On Oct 12, 4:24 am, WS3Z <critch...@gmail.com> wrote:
> All you C++ programmers say that. Too lazy to write your own code, ect.
> I learn much better from code examples that I can load up and play with,
> It might take a beginner to C++ a month to get the syntax correct and by
> then it would be thrown out the window.
>
> If OYC says its tricky then its not something for a beginner.
> Just my 2 cents on learning code.
>
> On Tue, Oct 12, 2010 at 4:55 AM, Christian Brugger <
>
> brugger....@googlemail.com> wrote:
> > Hi,
>
> > I think most of us would prefer helping you getting started, instead
> > of providing finished code.
>
> > As a community we don't want you to just copy&paste our code, we want
> > to help you learning to understand microcontrollers.
>
> > Some tutorials, you might have a look at:
>
> > - Using buttons to let LEDs blink:
> > --> basic:
> >http://mspsci.blogspot.com/2010/07/tutorial-07-pushing-buttons.html
> > --> using interrupts:
>
> >http://www.msp430launchpad.com/search?updated-max=2010-07-30T04:22:00...
>
> > - Setting up peripherals:
> > -->
> >http://mspsci.blogspot.com/2010/07/tutorial-02-msp430-township-and.html
>
> > If you wan't to reuse the Reset-Pin, you should have a look at the
> > PxSEL register in the user manual for a general explanation:
> >  -->http://focus.ti.com/lit/ug/slau144e/slau144e.pdf
>
> > And then at the datasheet of you specific chip, if you wan't to know
> > what the different PxSEL flags mean for the different inputs.
> > -->http://focus.ti.com/lit/ds/symlink/msp430g2231.pdf
>
> > Yeah you have to learn a lot at the beginning, but on the other hand,
> > what is it worth to rely on other's people code, you can copy&paste?
>
> > Christian
>
> > On Tue, Oct 12, 2010 at 8:14 AM, Kevin Mark <kevin.m...@verizon.net>
> > wrote:
> > > On Mon, Oct 11, 2010 at 11:43:53AM -0700, Old_Cow_Yellow wrote:
> > >> Actually, you could. But it is a little tricky.
>
> > >> Your firmware could setup the RSTn/NMI pin in the NMI mode to trigger
> > >> an interrupt at either the rising or falling edge. The enable bit and
> > >> edge select bit are in the WDTCTL register.
>
> > >> This is kind of nice because in addition to the 10 GPIO pins, you have
> > >> gained an additional input pin and on the LaunchPad, that pin is
> > >> already wired to a push-button with pull-up resistor. So out of a 14-
> > >> pin chip, you have 11 I/O pins. Not bad at all!
>
> > >> -- OCY
> > > for the newbies like me, could you write a small program to allow you to
> > blink
> > > LED1(P1.0)with the S1(reset)?
> > > --
> > > |  .''`.  == Debian GNU/Linux ==.|http://kevix.myopenid.com......|
> > > | : :' :     The Universal OS....| mysite.verizon.net/kevin.mark/.|<http://mysite.verizon.net/kevin.mark/.%7C>
> > > | `. `'  http://www.debian.org/.|<http://www.debian.org/.%7C>

Old_Cow_Yellow

unread,
Oct 29, 2010, 9:02:10 PM10/29/10
to TI Launchpad
/
*******************************************************************************
* Demo Program for LaunchPad
Board *
* Using S1 at nRST/NMI Pin as Input for
Application *
* OCY Oct
2010 *
*******************************************************************************/
#include <msp430.h>
#define FLIP_HOLD (0x3300 | WDTHOLD) /* flip HOLD while preserving
other bits */
//
#define S1_MAKE P1OUT |= BIT0 /* turn on LED1 for demo */
#define S1_BREAK P1OUT &= ~BIT0 /* turn off LED1 for demo */
//
void main (void)
{
// We use the red LED1 at P1.0 to demostrate that we can detect
// the switch s1 at nRST/NMI pin as an input
P1OUT &= ~BIT0;
P1DIR |= BIT0;
// The WDT will be used exclusively to debounce s1
WDTCTL = WDTPW | WDTHOLD | WDTNMIES | WDTNMI;
IFG1 &= ~(WDTIFG | NMIIFG);
IE1 |= WDTIE | NMIIE;
// The CPU is free to do other tasks, or go to sleep
__bis_SR_register(CPUOFF | GIE);
}
//
==============================================================================
// isr to detect make/break of s1 at the nRST/NMI pin
#pragma vector = NMI_VECTOR
__interrupt void nmi_isr(void)
{
if (IFG1 & NMIIFG) // nmi caused by nRST/NMI pin
{
IFG1 &= ~NMIIFG;
if (WDTCTL & WDTNMIES) // falling edge detected
{
S1_MAKE; // tell the rest of the world that s1 is depressed
WDTCTL = WDT_MDLY_32 | WDTNMI; // debounce and detect rising
edge
}
else // rising edge detected
{
S1_BREAK; // tell the rest of the world that s1 is released
WDTCTL = WDT_MDLY_32 | WDTNMIES | WDTNMI; // debounce and detect
falling edge
}
} // Note that NMIIE is cleared; wdt_isr will set NMIIE 32msec later
else {/* add code here to handle other kinds of nmi, if any */}
}
//
==============================================================================
// WDT is used exclusively to debounce s1 and re-enable NMIIE
#pragma vector = WDT_VECTOR
__interrupt void wdt_isr(void)
{
WDTCTL ^= FLIP_HOLD; // Flip the HOLD bit only, others remain
unchanged
IFG1 &= NMIIFG; // It may have been set by switch bouncing, clear it
IE1 |= NMIIE; // Now we can enable nmi to detect the next edge
}
//
==============================================================================

On Oct 12, 2:37 pm, Old_Cow_Yellow <lichen.wang.acti...@gmail.com>
wrote:

Kevin Mark

unread,
Oct 29, 2010, 11:32:22 PM10/29/10
to ti-lau...@googlegroups.com
On Fri, Oct 29, 2010 at 06:02:10PM -0700, Old_Cow_Yellow wrote:
> /
> *******************************************************************************
> * Demo Program for LaunchPad
> Board *
> * Using S1 at nRST/NMI Pin as Input for
> Application *
> * OCY Oct
> 2010 *
> *******************************************************************************/
> #include <msp430.h>

Thanks for attempting this challange! I will go over it and see what I can understand.


--
| .''`. == Debian GNU/Linux ==.| http://kevix.myopenid.com......|
| : :' : The Universal OS....| mysite.verizon.net/kevin.mark/.|

| `. `' http://www.debian.org/.| http://counter.li.org [#238656]|

Reply all
Reply to author
Forward
0 new messages