Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help on msp430 interrupt

Status
Not open for further replies.

btminzon

Full Member level 2
Joined
Jun 12, 2006
Messages
122
Helped
9
Reputation
18
Reaction score
1
Trophy points
1,298
Location
Brazil
Activity points
2,144
msp430 interrupts

Hi, i´m having some troubles with interrupt handling in C (IAR) with a MSP4302011. My code it seens like this:

#pragma vector=PORT2_VECTOR

__interrupt void p2_isr(void)
{

if ( (P2IN & 0xC0) == 0xC0)
counter++;

else if ( (P2IN & 0xC0) == 0x80)
counter--;

P2IFG = 0;

return;
}

in main func:

void main(void)
{
_EINT();

// Digitally-Controlled Oscillator (DCO) 16Mhz
BCSCTL1 = (unsigned char)CALBC1_16MHZ_;
DCOCTL = (unsigned char)CALDCO_16MHZ_;

// Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;

// Set P1.0 a P1.6 = OUT(LCD)
//P1.7 = IN(reset)
//P2 = OUT(encoder)
P1OUT = 0x00;
P1DIR = 0xfe;
P2DIR = 0x30;

// interrupt port 2
P2IE |= 0x01;

// Port 2: 0 to 1 edge
P2IES |= 0;

//enable interrupt on port 2
P2IFG = 0x00;

while(1)
{
...
some code here...
}

}


whats wrong in my interrupt routine? thanks
 

vhn

Member level 4
Joined
Sep 20, 2006
Messages
76
Helped
7
Reputation
14
Reaction score
2
Trophy points
1,288
Activity points
1,803
msp430 interrupt

Hi btminzon,
It is not advisable to put "return" statement at the end of ISR. Generally the compiler generates a "Return from Inerrupt" assembly instruction at the closing brace of the interrupt routine. But if you forcibly put "return", it may malfunction.
Some intelligent compilers do take care of this, but I'm not sure of IAR.

Just check the disassembly generated by the compiler. If there is not return from interrupt instruction, then that would be the cause of the problem you might be facing.

Regards,
vhn
 

    btminzon

    Points: 2
    Helpful Answer Positive Rating

btminzon

Full Member level 2
Joined
Jun 12, 2006
Messages
122
Helped
9
Reputation
18
Reaction score
1
Trophy points
1,298
Location
Brazil
Activity points
2,144
msp430 interrupt c

Hey Vhn, thanks for the help. In fact, the compiler add automatcaly the "reti" instruction, i didn´t have noticed this before, but the system doesn´t run properly... do you think that the routine to set the clock 16Mhz its ok? i need as fast as possible, with low power, thats why i choose this mc
 

yager

Member level 5
Joined
May 28, 2001
Messages
93
Helped
33
Reputation
66
Reaction score
14
Trophy points
1,288
Activity points
742
msp430 interrupt code

btminzon said:
Hi, i´m having some troubles with interrupt handling in C (IAR) with a MSP4302011.
The P2 only 2 I/O (P2.6/P2.7) are available for MSP430x20x1.
You have to set correct settings (P2SEL/P2DIR/P2IE/P2IES) for P2 interrupt.
btminzon said:
P2DIR = 0x30;
To affect P2.6/P2.7 only, so why 0x30?
btminzon said:
P2IE |= 0x01;
I doubt whether the P2 interrupt was happened.
(you enable P2.0 interrupt, where is P2.0 in MSP430F2011? BTW, cannot find P2.6/P2.7 interrupt be enable in your code).

FYR
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top