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.

[参考译文] CC2530:有关 CC2530的一些问题。

Guru**** 2466030 points
Other Parts Discussed in Thread: CC2530

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/zigbee-thread-group/zigbee-and-thread/f/zigbee-thread-forum/1133993/cc2530-some-issues-about-cc2530

器件型号:CC2530

大家好、

以下是客户的请求:

CC2530设置为首先在上升沿进行捕捉、并且在进入上升沿的捕捉中断后、它设置为在下降沿进行捕捉、以便测量高电平的时间。  但是、在使用它时、发现只有调试过程可以进入上升沿中断、但不能进入下降沿中断。

代码如下所示:

#include <ioCC2530.h>

typedef unsigned char uchar;
typedef unsigned int uint;

unsigned char irtime=0;
#define IR P1_0
#define uint32_t unsigned int
#define uint16_t unsigned short
#define uint8_t unsigned char


unsigned char receive_ok=1;
uint32_t upCount=0;
uint16_t valueDown=0;
uint16_t valueUp=0;
uint32_t width=0;
uint32_t isUpCap=1;
uint buffer[200]={0};
char bufferId=0;


//#define leng_23
//#define leng_21

#if defined leng_23
uint8_t leng=23;
uint8_t arr[23]={0x00};
#elif defined leng_21
uint8_t leng=21;
uint8_t arr[21]={0x00};
#else
uint8_t leng=17;
uint8_t arr[17]={0x00};
#endif

void IR_Init(void)
{
P1DIR&=0XFE;//P1.0 for input mode
P1SEL|=0X01;//Peripheral function

}
void InitUart(void)
{
PERCFG &= 0xF0; //The IO position of the peripheral control register USART 0: 0 is the P0 port position 1
P0SEL = 0x0c; //P0_2, P0_3 are used as serial ports (peripheral functions)
P2DIR &= ~0XC0; //P0 takes priority as UART0

U0CSR |= 0x80; //Set to UART mode
U0GCR |= 11;
U0BAUD |= 216; //Set the baud rate to 115200
UTX0IF = 0; //UART0 TX interrupt flag is initially set to 0
}
void UartSendString(uint *Data, int len)
{
uint i;

for(i=0; i<len; i++)
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
}
void InitT3(void)
{
T3CTL|=0X08;//Enable overflow interrupt
T3IE=1;//
Enable total interrupt and T3 interrupt
T3CTL|=0XE0;//128 frequency division

T3CTL&=~0X03;//auto reload
T3CTL|=0X10;//boot
EA=1;
}

void T1_Init(void)
{
PERCFG|=0X40;//Timer 1 Alternate Location 2
P2SEL&=0XEF;//Timer 1 takes precedence
T1CTL=0X0D;//128free running mode
T1CCTL2=0X41;//Rising edge capture, capture mode, timer 1 channel 2 timer enable
T1IE=1;
EA=1;//Timer 1 overflow interrupt is automatically turned on, in the register of TIMIF
}

uint ary[3]={1,2,3};


int main()
{

CLKCONCMD &= ~0x40; //Set the system clock source to 32MHZ crystal oscillator

while(CLKCONSTA & 0x40); //Wait for the crystal oscillator to stabilize to 32M
CLKCONCMD &= ~0x07; //Set the system main clock frequency to 32MHZ
IR_Init();
// Time1_Init();
T1_Init();

InitUart();
//UartSendString("usart is ok",11);
UartSendString(ary,3);
while(1)

{

if(receive_ok==0)
{
UartSendString(buffer, sizeof(buffer));
for(int ix=0;ix<200;ix++)
{
buffer[ix]=0x00;
}
receive_ok=1;


}

}

}

uint8_t a=0;


#pragma vector = T1_VECTOR
__interrupt void T1_ISR()
{
T1IF = 0;
T1STAT &= ~0x04;//clear interrupt flag
// if(T1STAT&(~0XDF))//Timer 1 overflow interrupt
// {
//
//
// irtime++;
//
// }


if(T1STAT&(~0XFB))//Edge-triggered interrupt, timer 1 channel 2 interrupt
{
if(isUpCap)//Determine whether it is a rising edge trigger
{
a=T1CC2H;
uint8_t b=T1CC2L;
valueUp=(a<<8)|b;
isUpCap=0;//Falling edge flag clear
T1CCTL2|=0X02;//Falling edge capture
irtime=0;//The overflow count value is set to 0
}
else
{


uint8_t c=T1CC2H;
uint8_t d=T1CC2L;
valueDown=(c<<8)|d;
//valueDown=(T1CC2H<<8)|T1CC2L;
isUpCap=1;//The rising edge of the flag bit is cleared
T1CCTL2|=0X01;//Rising edge capture
width=valueDown-valueUp+65536*irtime;//Calculate the time
if(bufferId>=1)
{
buffer[bufferId++]=width;
if(bufferId>184)
{
bufferId=0;
receive_ok=0;
}
}
}


}


}
//#pragma vector = T3_VECTOR
//__interrupt void T3_ISR()//2.1ms
//{
// IRCON=0X00;
// irtime++;
//}

您可以帮助检查此案例吗? 谢谢。

此致、                                                             

Nick     

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Nick、

    由于客户在 T1CCTL2上使用按位包含或赋值运算符"|="、因此最终结果将变为0x43表示"在所有边沿上捕获"、而不是表示其意图。  至于从不输入下降沿逻辑代码的原因、这可能是由于硬件引脚反弹或边沿被处理 ISR 所需的时间所错过(也可能是由于运行计时器时钟较慢或在调试器内暂停运行)。  在某些时候 、由于  T1CCTL2管理不善、进入这个部分将是预料之中的、从本质上讲、逻辑电路会在捕获模式和软件标志之间混淆。   

    此致、
    Ryan