This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

定时器无法进入中断

Other Parts Discussed in Thread: MSP430G2231

各位大神,我现在用的是MSP430G2231的芯片,但是在配置定时器时选择时钟时为TACLK,ACLK,INCLK,定时器无法进入中断,我的代码如下:
void timer0_init(void)
{
TA0CTL |= TASSEL_1+TACLR+MC_3+ID_0;

TA0CCR0 = 1024;//

TA0CCTL0 |= CCIE;
_EINT();
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer0_A0(void) //TACCR0中断
{
P1OUT^=BIT6;
}
}
如上代码, TASSEL_1应该是选择ACLK时钟源,但是进不了中断!除此之外,TACLK,INCLK设置为时钟源时,都进不了中断?
不知道什么原因引起?由于以前没接触过TI这款芯片,所以不太熟悉!

  • 请您试一下下面的程序

    /* --COPYRIGHT--,BSD_EX * Copyright (c) 2012, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************* * * MSP430 CODE EXAMPLE DISCLAIMER * * MSP430 code examples are self-contained low-level programs that typically * demonstrate a single peripheral function or device feature in a highly * concise manner. For this the code may rely on the device's power-on default * register values and settings such as the clock configuration and care must * be taken when combining code from several examples to avoid potential side * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware * for an API functional library-approach to peripheral configuration. * * --/COPYRIGHT--*/ //****************************************************************************** // MSP430G2xx1 Demo - Timer_A, Toggle P1.0, CCR0 Up Mode ISR, 32kHz ACLK // // Description: Toggle P1.0 using software and the TA_0 ISR. Timer_A is // configured for up mode, thus the the timer overflows when TAR counts // to CCR0. In this example, CCR0 is loaded with 1000-1. // Toggle rate = 32768/(2*1000) = 16.384Hz // ACLK = TACLK = 32768Hz, MCLK = SMCLK = DCO // //* An external watch crystal on XIN XOUT is required for ACLK *// // // MSP430G2xx1 // --------------- // /|\| XIN|- // | | | 32kHz // --|RST XOUT|- // | | // | P1.0|-->LED // // D. Dang // Texas Instruments Inc. // October 2010 // Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10 //****************************************************************************** #include <msp430.h> int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= 0x01; // P1.0 output CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 1000-1; TACTL = TASSEL_1 + MC_1; // ACLK, upmode __bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupt } // Timer A0 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) #elif defined(__GNUC__) void __attribute__ ((interrupt(TIMERA0_VECTOR))) Timer_A (void) #else #error Compiler not supported! #endif { P1OUT ^= 0x01; // Toggle P1.0 }

  • 你发的这个代码还是进不了中断,只有将77行代码TACTL = TASSEL_1 + MC_1;改为TACTL = TASSEL_2 + MC_1;(TASSEL_1改为TASSEL_2)才正常!
    为什么选择时钟为TASSEL_2时正常,但是选择TASSEL_1时异常进不了中断呢?
  • TASSEL_1(ACLK)内部时钟源,应该不需要焊接外部晶振吧?
  • 不需要接外部晶振

    以下是我用G2553的launchpad和您的程序来测试的。

    结果显示可以进入中断

  • 非常感谢你,已解决,是因为时钟配置不合适!
  • 很高兴您能解决问题!
  • 打扰了,想问下是如何配置的 ,我也遇到了相同的情况 。pwm可以输出 但是无法进入中断函数