Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Timer MSP 430G2553在带有定时器的比较模式下采样_Timer_Embedded_Msp430 - Fatal编程技术网

Timer MSP 430G2553在带有定时器的比较模式下采样

Timer MSP 430G2553在带有定时器的比较模式下采样,timer,embedded,msp430,Timer,Embedded,Msp430,朋友们,我必须采样的输入,每14微秒在61微秒插槽与定时器输入(项目要求) 我必须做8次才能得到一个字节。更像UART,但我正在为我的Masters项目使用它进行单线总线通信 我编写了如下代码,给出了预期的结果,并在调试器中一次执行一条指令进行了测试 下面是代码 /***************************************************************************** COMPARE MODE SAMPLING: MCLK and SCLK

朋友们,我必须采样的输入,每14微秒在61微秒插槽与定时器输入(项目要求)

我必须做8次才能得到一个字节。更像UART,但我正在为我的Masters项目使用它进行单线总线通信

我编写了如下代码,给出了预期的结果,并在调试器中一次执行一条指令进行了测试

下面是代码

/*****************************************************************************

COMPARE MODE SAMPLING:


MCLK and SCLK @8MZ

The code configures P2.1  as TA1.CCI1A input.
It samples the input at P2.1 Whenever the TA1R reaches the TA1CCR1 value.

It samples input on P2.1 every 14us once in a duration of 61 us.

It then reads 8 bits one by one to read a byte.

******************************************************************************/

#include "io430g2553.h"

#define MSP_DQ BIT5


unsigned char word=0x00;



unsigned char i=0;
unsigned char temp;

void Read(void)
{

TA1CCR0 = 0x1E8; //  61 micro secs




TA1CCR1 = 0x70; // 14 micro secs

//TA0CCTL1 = CM_2 | CCIS_0 | SCS | CAP | OUTMOD_0 | CCIE;
//Keep in mind that It should not be configured as campture mode

TA1CCTL1 |= CM_2 | CCIS_0 | SCS | OUTMOD_0 | CCIE;

TA1CTL = TASSEL_2 + MC_1 + ID_0; // Register TA0CTL -> SMCLK/1, Up mode

do{

while ((TA1CCTL0 & CCIFG) == 0 ) // wait while CCIF is set
{
}

**TA1CCTL0 &= ~CCIFG; // Clear the flag** (%1%)
//TA1CTL &= ~TAIFG; // Clear the flag
i++;
} while( i<8) ;

TA1CTL = TACLR; // Stop the Timer
TA1CCTL1 = 0x00;

}

void Configure_CCI1A(void)
{

// Configuring P2.1 as TA1.CCI1A

P2OUT &= 0x00; // Clearing P1OUT
P2DIR &= ~BIT1 ; // Configuring P1.2 as input
P2SEL |= BIT1 ; // P2.1 Timer1_A, capture: CCI1A input, compare: Out1 output
P2SEL2 &= ~BIT1 ;


}


void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;

P1OUT &= 0x00; // Clearing P1OUT
P1DIR |= BIT0 ; // Configuring P1.0 as Output

__enable_interrupt();

Configure_CCI1A();
Read();

**P1OUT ^= BIT0;** //(%2%)


while(1) {

}
}


// Timer A1 interrupt service routine
#pragma vector=TIMER1_A1_VECTOR
__interrupt void Timer1_A1 (void)
{

P1OUT ^= BIT0; // To show Read occured

word <<=1; // If x = 00000010 (binary) => x <<= 2; => x=00001000
temp=0x00;
temp=((TA1CCTL1 & SCCI)>>10);
**word = word + temp ;** //(%3%)

}
/*****************************************************************************
比较模式采样:
8MHz时的MCLK和SCLK
代码将P2.1配置为TA1.CCI1A输入。
每当TA1R达到TA1CCR1值时,它在P2.1处对输入进行采样。
它在61 us的持续时间内每14 us对P2.1上的输入进行一次采样。
然后,它逐个读取8位以读取一个字节。
******************************************************************************/
#包括“io430g2553.h”
#定义MSP_DQ位5
无符号字符字=0x00;
无符号字符i=0;
无符号字符温度;
无效读取(无效)
{
TA1CCR0=0x1E8;//61微秒
TA1CCR1=0x70;//14微秒
//TA0CCTL1=CM|2 | CCIS|0 | SCS | CAP | OUTMOD|0 | CCIE;
//请记住,不应将其配置为campture模式
TA1CCTL1 |=CM | 2 | CCIS | 0 | SCS | OUTMOD | 0 | CCIE;
TA1CTL=TASSEL_2+MC_1+ID_0;//寄存器TA0CTL->SMCLK/1,上行模式
做{
while((TA1CCTL0&CCIFG)==0)//设置CCIF时等待
{
}
**TA1CCTL0&=~CCIFG;//清除标志**(%1%)
//TA1CTL&=~TAIFG;//清除标志
i++;

}而(i当您读取TAIV或在TACCTL1中手动清除时,中断标志将自动清除。但是,您在ISR中不执行这两项操作,因此中断将保持挂起状态,CPU将继续执行ISR,而不会执行其他代码,因此它永远不会有机会退出
read()


我的猜测是,通过在ISR中设置断点,您的开发环境会导致从TAIV读取并清除挂起的中断。我以前经历过这种情况,但不确定这种行为有多普遍,因为它是不受欢迎的。

谢谢..Tinman..我发现昨天读了John Davies的书…在中添加了TA1CCTL1&=~CCIFGISR是ISR的产物。这也是你的建议。干杯
while ((TA1CCTL0 & CCIFG) == 0 ) // wait while CCIF is set
{
} 

and

{

....

....

i++;

} while( i<8) ;