最近有个项目,需要使用到MSP430F2132.需要用到捕获功能,MSP430F2132中的TA0中的捕获引脚有3个,分别对应CCR0(P1.1),CCR1(P1.2),CCR3(P1.3),目前P1.1和P1.2我做其他用途,现在用P1.3引脚做捕获,发现第一次能进入捕获中断,之后就不能进中断了,这到底是怎么回事?请大家指教指教!!
附上相关代码:
gpio设置:
void GPIO_Init(void)
{
P1DIR &= (~BIT3);
P1SEL |= (BIT3);
P1SEL2 |= (BIT3);
}
捕获功能设置:
void T0A3_cap_Init(void)
{
TA0CTL |= TASSEL_2 +ID_0 + MC_2;
TA0CCTL2 |= CM_2; // 下降沿捕获
TA0CCTL2 |= CCIS_0; // CCI2A做捕获输入
TA0CCTL2 |= SCS; // 同步方式
TA0CCTL2 |= CAP; // 捕获方式,
TA0CCTL2 |= CCIE;
}
中断函数:
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TIMER0_A3_CAP_ISR(void)
{
switch(__even_in_range(TAIV,10))
{
case 2: // P1.2捕获
break;
case 4: // P1.3捕获
Period1tmp = TA0CCR2;
Period1new = Period1tmp – Period1old;
Period1old = Period1tmp;
break;
case 10:
break;
}
}
注:我将P1.2做捕获测试了一下,是可以进入捕获程序的,为什么P1.3不行?
HG:
P1.3是TA0.2
#pragma vector=TIMER0_A2_VECTOR__interrupt void Timer0_A2 (void)
user1003689:
回复 HG:
你好,谢谢你的回复。
在MSP430F2132。h的头文件里没有和你提供的中断向量:
/************************************************************* Interrupt Vectors (offset from 0xFFE0)************************************************************/#define VECTOR_NAME(name) name##_ptr#define EMIT_PRAGMA(x) _Pragma(#x)#define CREATE_VECTOR(name) void (* const VECTOR_NAME(name))(void) = &name#define PLACE_VECTOR(vector,section) EMIT_PRAGMA(DATA_SECTION(vector,section))#define ISR_VECTOR(func,offset) CREATE_VECTOR(func); \ PLACE_VECTOR(VECTOR_NAME(func), offset)#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define PORT1_VECTOR ".int02" /* 0xFFE4 Port 1 */#else#define PORT1_VECTOR (2 * 1u) /* 0xFFE4 Port 1 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define PORT2_VECTOR ".int03" /* 0xFFE6 Port 2 */#else#define PORT2_VECTOR (3 * 1u) /* 0xFFE6 Port 2 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define ADC10_VECTOR ".int05" /* 0xFFEA ADC10 */#else#define ADC10_VECTOR (5 * 1u) /* 0xFFEA ADC10 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define USCIAB0TX_VECTOR ".int06" /* 0xFFEC USCI A0/B0 Transmit */#else#define USCIAB0TX_VECTOR (6 * 1u) /* 0xFFEC USCI A0/B0 Transmit */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define USCIAB0RX_VECTOR ".int07" /* 0xFFEE USCI A0/B0 Receive */#else#define USCIAB0RX_VECTOR (7 * 1u) /* 0xFFEE USCI A0/B0 Receive */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER0_A1_VECTOR ".int08" /* 0xFFF0 Timer0 A CC1-2, TA */#else#define TIMER0_A1_VECTOR (8 * 1u) /* 0xFFF0 Timer0 A CC1-2, TA */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER0_A0_VECTOR ".int09" /* 0xFFF2 Timer0 A CC0 */#else#define TIMER0_A0_VECTOR (9 * 1u) /* 0xFFF2 Timer0 A CC0 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define WDT_VECTOR ".int10" /* 0xFFF4 Watchdog Timer */#else#define WDT_VECTOR (10 * 1u) /* 0xFFF4 Watchdog Timer */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define COMPARATORA_VECTOR ".int11" /* 0xFFF6 Comparator A */#else#define COMPARATORA_VECTOR (11 * 1u) /* 0xFFF6 Comparator A */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER1_A1_VECTOR ".int12" /* 0xFFF8 Timer1 A CC1-2, TA */#else#define TIMER1_A1_VECTOR (12 * 1u) /* 0xFFF8 Timer1 A CC1-2, TA */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER1_A0_VECTOR ".int13" /* 0xFFFA Timer1 A CC0 */#else#define TIMER1_A0_VECTOR (13 * 1u) /* 0xFFFA Timer1 A CC0 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define NMI_VECTOR ".int14" /* 0xFFFC Non-maskable */#else#define NMI_VECTOR (14 * 1u) /* 0xFFFC Non-maskable */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define RESET_VECTOR ".reset" /* 0xFFFE Reset [Highest Priority] */#else#define RESET_VECTOR (15 * 1u) /* 0xFFFE Reset [Highest Priority] */#endif
还有,在MSP430F2132的Datasheet中,对这个向量有如下所示:
还有:
user1003689:
回复 HG:
你好,谢谢你的回复。
在MSP430F2132。h的头文件里没有和你提供的中断向量:
/************************************************************* Interrupt Vectors (offset from 0xFFE0)************************************************************/#define VECTOR_NAME(name) name##_ptr#define EMIT_PRAGMA(x) _Pragma(#x)#define CREATE_VECTOR(name) void (* const VECTOR_NAME(name))(void) = &name#define PLACE_VECTOR(vector,section) EMIT_PRAGMA(DATA_SECTION(vector,section))#define ISR_VECTOR(func,offset) CREATE_VECTOR(func); \ PLACE_VECTOR(VECTOR_NAME(func), offset)#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define PORT1_VECTOR ".int02" /* 0xFFE4 Port 1 */#else#define PORT1_VECTOR (2 * 1u) /* 0xFFE4 Port 1 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define PORT2_VECTOR ".int03" /* 0xFFE6 Port 2 */#else#define PORT2_VECTOR (3 * 1u) /* 0xFFE6 Port 2 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define ADC10_VECTOR ".int05" /* 0xFFEA ADC10 */#else#define ADC10_VECTOR (5 * 1u) /* 0xFFEA ADC10 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define USCIAB0TX_VECTOR ".int06" /* 0xFFEC USCI A0/B0 Transmit */#else#define USCIAB0TX_VECTOR (6 * 1u) /* 0xFFEC USCI A0/B0 Transmit */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define USCIAB0RX_VECTOR ".int07" /* 0xFFEE USCI A0/B0 Receive */#else#define USCIAB0RX_VECTOR (7 * 1u) /* 0xFFEE USCI A0/B0 Receive */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER0_A1_VECTOR ".int08" /* 0xFFF0 Timer0 A CC1-2, TA */#else#define TIMER0_A1_VECTOR (8 * 1u) /* 0xFFF0 Timer0 A CC1-2, TA */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER0_A0_VECTOR ".int09" /* 0xFFF2 Timer0 A CC0 */#else#define TIMER0_A0_VECTOR (9 * 1u) /* 0xFFF2 Timer0 A CC0 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define WDT_VECTOR ".int10" /* 0xFFF4 Watchdog Timer */#else#define WDT_VECTOR (10 * 1u) /* 0xFFF4 Watchdog Timer */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define COMPARATORA_VECTOR ".int11" /* 0xFFF6 Comparator A */#else#define COMPARATORA_VECTOR (11 * 1u) /* 0xFFF6 Comparator A */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER1_A1_VECTOR ".int12" /* 0xFFF8 Timer1 A CC1-2, TA */#else#define TIMER1_A1_VECTOR (12 * 1u) /* 0xFFF8 Timer1 A CC1-2, TA */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define TIMER1_A0_VECTOR ".int13" /* 0xFFFA Timer1 A CC0 */#else#define TIMER1_A0_VECTOR (13 * 1u) /* 0xFFFA Timer1 A CC0 */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define NMI_VECTOR ".int14" /* 0xFFFC Non-maskable */#else#define NMI_VECTOR (14 * 1u) /* 0xFFFC Non-maskable */#endif#ifdef __ASM_HEADER__ /* Begin #defines for assembler */#define RESET_VECTOR ".reset" /* 0xFFFE Reset [Highest Priority] */#else#define RESET_VECTOR (15 * 1u) /* 0xFFFE Reset [Highest Priority] */#endif
还有,在MSP430F2132的Datasheet中,对这个向量有如下所示:
还有:
user1003689:
回复 user1003689:
HG:
回复 user1003689:
ohhh,我想你是对的,确实是TIMER0的A3和TIMER1的A2支持Capture
P1.3对应TA0.2是Timer0_A3, capture: CCI2A input,Sorry啦