TI中文支持网
TI专业的中文技术问题搜集分享网站

定时器无法进入中断

各位大神,我现在用的是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这款芯片,所以不太熟悉!

Susan Yang:

请您试一下下面的程序/* --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
//--|RSTXOUT|-
//||
//|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 WDTP1DIR |= 0x01;// P1.0 outputCCTL0 = CCIE;// CCR0 interrupt enabledCCR0 = 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
}

user6105265:

回复 Susan Yang:

你发的这个代码还是进不了中断,只有将77行代码TACTL = TASSEL_1 + MC_1;改为TACTL = TASSEL_2 + MC_1;(TASSEL_1改为TASSEL_2)才正常!
为什么选择时钟为TASSEL_2时正常,但是选择TASSEL_1时异常进不了中断呢?

user6105265:

回复 Susan Yang:

TASSEL_1(ACLK)内部时钟源,应该不需要焊接外部晶振吧?

user6105265:

回复 Susan Yang:

非常感谢你,已解决,是因为时钟配置不合适!

Susan Yang:

回复 user6105265:

很高兴您能解决问题!

user6095721:

回复 user6105265:

打扰了,想问下是如何配置的 ,我也遇到了相同的情况。pwm可以输出 但是无法进入中断函数

赞(0)
未经允许不得转载:TI中文支持网 » 定时器无法进入中断
分享到: 更多 (0)