O'Reilly logo

Microcontroller Programming and Interfacing Texas Instruments MSP430 by Daniel J. Pack, Steven F. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

234 7. RESETS AND INTERRUPTS
,QWHUUXSWYHFWRUUHJLVWHU 7\SH 2IIVHWYDOXH 3ULRULW\
6<6567,9(K 1RLQWHUUXSW K
6\VWHP5HVHW %URZQRXW%25 K +LJKHVW
57610,325 K
3006:%25%25 K
5HVHUYHG K
6HFXULW\YLRODWLRQ%25 $K
696/325 &K
696+325 (K
690/B293325 K
690+B293325 K
3006:325325 K
:'7WLPHRXW38& K
:'7SDVVZRUGYLRODWLRQ38& K
.(<9IODVKSDVVZRUGYLRODWLRQ38& $K
)//XQORFN38& &K
3HULSKHUDODUHDIHWFK38& (K
300SDVVZRUGYLRODWLRQ38& K
5HVHUYHG K(K /RZHVW
6<661,96<6((010,&K 1RLQWHUUXSW K
690/,)* K +LJKHVW
690+,)* K
6960/'<,)* K
6960+'<,)* K
90$,)* $K
-0%,1,)* &K
-0%287,)* (K
690/9/5,)* K
690+9/5,)* K
5HVHUYHG K(K /RZHVW
6<681,98VHU10,$K 1RLQWHUUXSW K
10,)* K +LJKHVW
2),)* K
$&&9,)* K
5HVHUYHG K(K /RZHVW
Figure 7.14: Interrupt vector offset values.
case 0: break; // No interrupt
case 2: break; // CCR1 not used
case 4: break; // CCR2 not used
case 6: break; // reserved
case 8: break; // reserved
case 10: break; // reserved
case 12: break; // reserved
case 14: P1OUT ˆ= 0x01; // overflow
break;
default: break;
}
}
7.5. INTERRUPTS 235
7$B,65 $'' 7$,93& $GGRIIVHWWRMXPSWDEOH
5(7, 1RLQWHUUXSW
-03 &&,)*B,65 YHFWRU
-03 &&,)*B,65 YHFWRU
-03 &&,)*B,65 YHFWRU
7$,)*B,65 YHFWRU
5(7,
&&,)*B,65 ,65IRUYHFWRU
5(7,
&&,)*B,65 ,65IRUYHFWRU
5(7,
&&,)*B,65 ,65IRUYHFWRU
5(7,
Figure 7.15: Timer_A Interrupt Service Routine.
//***********************************************************************
In this example, the MSP430F5438 Timer_A is again used with multiple interrupts.
//***********************************************************************
//MSP430F5438 Demo - Timer_A3, Toggle P1.0;P2.1-3, Cont. Mode ISR
//
//Description: Use Timer1_A CCRx units and overflow to generate four
//independent timing intervals. For demonstration, CCR0, CCR1 and CCR2
//output units are optionally selected with port pins P2.1, P2.2 and P2.3
//in toggle mode. As such, these pins will toggle when respective CCRx
//registers match the TAR counter. Interrupts are also enabled with all
//CCRx units, software loads offset to next interval only - as long as
//the interval offset is added to CCRx, toggle rate is generated in
//hardware. Timer1_A overflow ISR is used to toggle P1.0 with software.
//
//Proper use of the TAIV interrupt vector generator is demonstrated.
//ACLK = TACLK = 32kHz, MCLK = SMCLK = default DCO ˜1.045MHz
//
//As coded and with TACLK = 32768Hz, toggle rates are:
236 7. RESETS AND INTERRUPTS
// P2.1= CCR0 = 32768/(2*4) = 4096Hz
// P2.2= CCR1 = 32768/(2*16) = 1024Hz
// P2.3= CCR2 = 32768/(2*100) = 163.84Hz
// P1.0= overflow = 32768/(2*65536) = 0.25Hz
//
//M Smertneck / W. Goh
//Texas Instruments Inc.
//September 2008
//Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B
//***********************************************************************
#include "msp430x54x.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop WDT
P2SEL |= 0x0E; //P1.1 - P1.3 option select
P2DIR |= 0x0E; //P2.1 - P2.3 outputs
P1DIR |= 0x01; //P1.0 - Outputs
TA1CCTL0 = OUTMOD_4 + CCIE; //CCR0 toggle,interrupt enabled
TA1CCTL1 = OUTMOD_4 + CCIE; //CCR1 toggle,interrupt enabled
TA1CCTL2 = OUTMOD_4 + CCIE; //CCR2 toggle,interrupt enabled
TA1CTL = TASSEL_1 + MC_2 + TACLR + TAIE; //ACLK, cont mode, clear TAR,
//interrupt enabled
__bis_SR_register(LPM3_bits + GIE); //Enter LPM3,interrupts enabled
__no_operation(); //For debugger
}
//***********************************************************************
// Timer1 A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer_A0 (void)
{
TA1CCR0 += 4; //Add Offset to CCR0
}
//***********************************************************************
7.5. INTERRUPTS 237
// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMER1_A1_VECTOR
__interrupt void TIMER1_A1_ISR(void)
{
switch(__even_in_range(TA1IV,14))
{
case 0: break;
case 2: TA1CCR1 += 16; //Add Offset to CCR1
break;
case 4: TA1CCR2 += 100; //Add Offset to CCR2
break;
case 6: break; // CCR3 not used
case 8: break; // CCR4 not used
case 10: break; // CCR5 not used
case 12: break; // Reserved not used
case 14: P1OUT ˆ= 0x01; // overflow
break;
default: break;
}
}
//***********************************************************************
In this final example, the Watchdog Timer interrupt to toggle MSP430 microcontroller pin
P1.0.
//***********************************************************************
//MSP430FG54x Demo - WDT, Toggle P1.0, Interval Overflow ISR, DCO SMCLK
//
//Description: Toggle P1.0 using software timed by the WDT ISR. Toggle
//rate is approximately 30ms = {(default DCO 1.045MHz) / 32768} based on
//default DCO/SMCLK clock source used in this example for the WDT.
//ACLK = n/a, MCLK = SMCLK = default DCO ˜1.045MHz

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required