按照TI提供的计时器中断控制LED灯闪烁的例程中,在中断函数中加入了一个计数器TxCycleCnt,并在计数大于10后disble CCIE,在main函数中加入了另外两个计数器a和b, 调试中发现,每次计时器中断发生后,执行计时器中断ISR后并没有回到main函数执行 b++ 的操作。 在TxCycleCnt大于10后,CCIE被置0,但是仍然没有回到主程序执行 b++。 请问应该如何理解? 我实际上是想实现触发10次中断后就disble CCIE,直到下次在主程序中 使能 CCIE再触发计时器中断。
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Application Defines */
#define TIMER_PERIOD 0x2DC6
unsigned int a = 0;
unsigned int b = 0;
unsigned int TxCycleCnt = 0;
/* Timer_A UpMode Configuration Parameter */
const Timer_A_UpModeConfig upConfig =
{
TIMER_A_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
TIMER_A_CLOCKSOURCE_DIVIDER_64, // SMCLK/1 = 3MHz
TIMER_PERIOD, // 5000 tick period
TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer interrupt
TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE , // Enable CCR0 interrupt
TIMER_A_DO_CLEAR // Clear value
};
int main(void)
{
/* Stop WDT */
MAP_WDT_A_holdTimer();
/* Configuring P1.0 as output */
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
/* Configuring Timer_A1 for Up Mode */
MAP_Timer_A_configureUpMode(TIMER_A1_BASE, &upConfig);
/* Enabling interrupts and starting the timer */
MAP_Interrupt_enableSleepOnIsrExit();
MAP_Interrupt_enableInterrupt(INT_TA1_0);
MAP_Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE);
/* Enabling MASTER interrupts */
MAP_Interrupt_enableMaster();
/* Sleeping when not in use */
while (1)
{
if (TxCycleCnt == 0){ a++; }
b++;
}
}
void TA1_0_IRQHandler(void)
{
MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_0);
TxCycleCnt++;
if (TxCycleCnt > 10) {
MAP_Timer_A_disableCaptureCompareInterrupt(TIMER_A1_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_0);
}
}
Yukang Xue:
找到问题了,Interrupt_enableSleepOnIsrExit() 使得除了ISR以外,处理器都在休眠。
,
Susan Yang:
很高兴您能解决问题。谢谢分享解决方法!