Jump to content
Sign in to follow this  
aymeric

MSP430g2231 two interrupts

Recommended Posts

hello.

 

I want to progam a msp430G2231 with two interrupts. With one interrupt no problem but if i want to use 2 interrupts how can i define that this interrupt is for this pin and the other for a this pin(and the same for a timer interrupt) . When I initialise the interrupt I never choosed the name of the interrupt fonction coressponding, I can choose no matter what name.

 

Then how can I use 2 various interrupts in a same program ?

 

Thank you.

Share this post


Link to post
Share on other sites

Hi,

 

The I/O port on the MSP430g2231 has only a single interrupt, meaning that you only can have one handler to deal with interrupts triggered by I/O pins. However, you can use the interrupt flag register, P1IFG, to determine which pin has triggered the interrupt. Note, also, that you have to reset the corresponding bit in P1IFG in your interrupt handler.

A quick example:

#pragma vector=PORT1_VECTOR
__interrupt void port1_Interrupt (void)
{
 if( P1IFG & BIT0 ) {
   // PIN 0 triggered the interrupt
   // Do stuff

   // Reset the interrupt flag
   P1IFG &= ~BIT0;
 }
 if (P1IFG & BIT5) {
   // PIN 5 triggered the interrupt
   // Do stuff

   // Reset the interrupt flag
   P1IFG &= ~BIT5;
 }
}

 

There are two time interrupts on the mgsp430g2231: TIMERA0 and TIMERA1. In compare mode TIMERA0 is triggered when CCR0 is reached, while TIMERA1 is triggered when CCR1 is reached, and TAR overflows. So, in a TIMERA1 interrupt handler you will have to check TAIV to see if the interrupt was triggered by CCR1 or TAR overflow.

 

Cheers,

Paul

Share this post


Link to post
Share on other sites

You can also use both ports, P1 and P2 which have separate interrupt vectors.

 

#pragma vector=PORT1_VECTOR
__interrupt void port1_Interrupt (void) { }

#pragma vector=PORT2_VECTOR
__interrupt void port2_Interrupt (void) { }

 

Another tip, if you need your interrupt triggered on both edges, tie two pins together.

Share this post


Link to post
Share on other sites
You can also use both ports, P1 and P2 which have separate interrupt vectors.

Doh, of course. I keep forgetting those two P2 pins :-)

 

Another tip, if you need your interrupt triggered on both edges, tie two pins together.

 

That's clever.

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