Jump to content
Sign in to follow this  
Bellmar

Embarissingly simple interrupt issue

Recommended Posts

So I have spent the last 8 hours trying to use NJC's code from his "Launchpad Example Project Ripped Open" post on his blog to send a single byte every time the user presses the p1.3 button. However, it never worked when I pressed the button. So I decided to test my understanding of Input interrupts with a simple LED toggle program based on P1 interrupts.

 

Edit: I forgot to mention that I was using a LaunchPad. Fixed some spelling as well.

 

What is weird is that this code only "sometimes" works. I download and debug in EW, allow it to run freely, and then press the button, and nothing happens. Other times it does. I just don't know what the deal is. I did notice that sometimes when I would press the button, the IF for some of the OTHER pins on P1 would go high, but not P1.3, which makes absolutely no sense. I tried configuring all the unused pins as outputs, which I should be doing anyway, but that didn't change anything.

 

In short: I'm an idiot, the interrupt which is supposed to toggle the LEDs does not, do yall have any input?

 

include

#include

#include

#include

 

#define BUTTON BIT3

#define LED1 BIT0

#define LED2 BIT6

 

void ledToggle(void);

 

void main(void)

{

WDTCTL = WDTPW + WDTHOLD;

 

BCSCTL1 = CALBC1_1MHZ; // Set range

DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz

 

P1DIR = 0xff; // set all pins to output

P1OUT = LED2; // set LED2 on at first

 

P1DIR &= ~BUTTON; //and Button in

P1REN |= BUTTON; // enable pull-up resistor

P1IES = BUTTON; // set to interrupt on high to low

P1IFG = 0x00; // disable interrupt flag before enabling interrupt

P1IE = BUTTON; // enable P1 on P1.3interrupt

__bis_SR_register(GIE); // enable general interrupts

 

LPM0; // start low power mode 0

}

 

#pragma vector = PORT1_VECTOR

__interrupt void Button_Press(void)

{

P1OUT ^= (LED2|LED1); // toggle LEDs

P1IFG = 0x00; // clear P1IFGs

}

Share this post


Link to post
Share on other sites

1. There's no de-bouncing (well, there is hardware one, but still,) so it's possible that you are generating multiple interrupts with one push.

2. You do not need pull-up resistor on P1.3 as there is already one, external.

3. Your pull-up resistor is actually pull-down resistor because you didn't set P1OUT to 1, so your external resistor is pulling up and your internal down, so most likely you are somewhere in the middle :) P1OUT |= BUTTON will select pull-up.

4. Writing to P1OUT or to P1DIR can affect P1IFG flags, I wouldn't worry about this as long as individual P1IEs are disabled.

Other than that I think it looks good.

 

Also, with port interrupts you can go as high as LPM4.

Share this post


Link to post
Share on other sites

The button S2 might bounce. If it bounces an odd number of times, it appears to be "working". But if it bounces an even number of time, it appears to be "not working".

Share this post


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.

Sign in to follow this  

×
×
  • Create New...