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.

cc430 程序跑时间长了后进入reset_vector

Other Parts Discussed in Thread: CC1101

如图,CC430的收发程序,等时间长了之后,程序就飞了,一直在reset_vector中不动了,不知道是什么情况。

  • 请把代码发上来看一看,程序跑飞的原因很多种

  • 这种问题在CC430里一般都是由于数组越界引起的,建议检查你的收发双方的数组长度定义。

  • /******************************************************************************

    * CC430 RF Code Example - TX and RX (variable packet length =< FIFO size)

    *

    * Simple RF Link to Toggle Receiver's LED by pressing Transmitter's Button    

    * Warning: This RF code example is setup to operate at either 868 or 915 MHz,

    * which might be out of allowable range of operation in certain countries.

    * The frequency of operation is selectable as an active build configuration

    * in the project menu.

    *

    * Please refer to the appropriate legal sources before performing tests with

    * this code example.

    *

    * This code example can be loaded to 2 CC430 devices. Each device will transmit

    * a small packet upon a button pressed. Each device will also toggle its LED

    * upon receiving the packet.

    *

    * The RF packet engine settings specify variable-length-mode with CRC check

    * enabled. The RX packet also appends 2 status bytes regarding CRC check, RSSI

    * and LQI info. For specific register settings please refer to the comments for

    * each register in RfRegSettings.c, the CC430x613x User's Guide, and/or

    * SmartRF Studio.

    *

    * M. Morales

    * Texas Instruments Inc.

    * February 2010

    * Built with IAR v4.21 and CCS v4.1

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

    #include "stdlib.h"

    #include "stdio.h"

    #include "../inc/RF_Toggle_LED_Demo.h"

    #include "../inc/usart.h"

    #include "../inc/press.h"

    #include "../inc/gprs.h"

    #include "../inc/time.h"

    #include "../inc/ds18b20.h"

    #include "cc430x613x.h"

    #define  PACKET_LEN         (0x05) // PACKET_LEN <= 61

    #define  RSSI_IDX           (PACKET_LEN+1)  // Index of appended RSSI

    #define  CRC_LQI_IDX        (PACKET_LEN+2)  // Index of appended LQI, checksum

    #define  CRC_OK             (BIT7)          // CRC_OK bit

    // 433MHz下的发射功率宏定义

    #define  PATABLE_VAL        (0xc4)          // 0XC4-- 10 dBm;

                                               // 0X50-- 0  dBm;

                                               // 0X2D-- -6 dBm;

                                               // 0X26-- -12dBm;

                                               // 0x05-- -30dBm;

                                               // 0xc0-- max

    #define  LED_RBIT           6

    #define  LED_GBIT           7

    #define  LED_DIR            P2DIR

    #define  LED_OUT            P2OUT

    #define  LED_SEL            P2SEL

    #define  LEDR_ON()          LED_OUT|=(1<<LED_RBIT)

    #define  LEDG_ON()          LED_OUT|=(1<<LED_GBIT)

    #define  LEDR_OFF()         LED_OUT&=~(1<<LED_RBIT)

    #define  LEDG_OFF()         LED_OUT&=~(1<<LED_GBIT)

    #define  BUTTON_BIT         0

    #define  BUTTON_DIR         PJDIR

    #define  BUTTON_OUT         PJOUT

    #define  BUTTON_REN         PJREN

    #define  BUTTON_IN          PJIN

    #define WDT_ARST_20s       (WDTPW+WDTCNTCL+WDTSSEL0+WDTIS2)                         /* 1000ms  " */

    extern RF_SETTINGS rfSettings;

    u4 Unknow_Flg=0;

    u4 Low_Flg=0;

    unsigned char packetReceived;

    unsigned char packetTransmit;

    no_init unsigned char RxBuffer[64];

    unsigned char RxBufferLength = 0;

    unsigned char buttonPressed = 0;

    unsigned int i = 0;

    unsigned char transmitting1= 0;

    unsigned char receiving = 0;

    void main( void )

    {//  u16 press_value;

     // u8  buff[10];

     // Stop watchdog timer to prevent time out reset

     WDTCTL = WDTPW + WDTHOLD; //关闭看门狗

    //  WDTCTL = WDT_ARST_250;  

     Sys_Init();

     Time_Init();

     // Increase PMMCOREV level to 2 for proper radio operation

     SetVCore(2);         //提升内核电压 PMM Core Voltage 2 (1.75V)                        

     ResetRadioCore();    //复位cc430 里面的Radio  

     InitRadio();        //初始化CC430 的Radio 模块

     InitButtonLeds();  //初始化按键和LED

    //  Usart_Init();  

    // simsend_init();

    //  Catch_Init();

     ReceiveOn();      //开启接收模式

    // ReceiveOff();

     P1DIR |= BIT0;

     P1DIR |= BIT1;

     P1DIR |= BIT2;

     P1DIR |= BIT3;

     P3DIR |= BIT6;

     P1OUT=0x00;

     P3OUT&=~BIT6;

     receiving = 1;

     _EINT();

         P2DIR |= BIT1;

       P2OUT |= BIT1;

           __bis_SR_register( GIE );

    //  __bis_SR_register(GIE);       // Enter LPM0, enable interrupts

    //  __no_operation();                         // For debugger*/

     while (1)

     {

    //   ReceiveOn();

       if(Unknow_Flg)

       {

          P1OUT=0X00;

          Delay_ms(150);

          P1OUT=0X0f;

          Delay_ms(150);

       }

           if(Low_Flg)

       {

          P1OUT=0X00;

          P3OUT&=~BIT6;

          Delay_ms(150);

          P1OUT=0X0f;

          P3OUT|=BIT6;

          Delay_ms(150);

       }

    //    WDTCTL = WDT_ARST_250;

    //    __no_operation();

     //  ReceiveOn();

    /*    if(!(BUTTON_IN & (1<<BUTTON_BIT)))

       {

    //     press_value=press_out();

    //     sprintf(buff,"5%05d",press_value);

         _NOP();

         delayms(30);

         if(!(BUTTON_IN & (1<<BUTTON_BIT)))

         {

           _NOP();

           LEDR_ON();

           ReceiveOff();

           receiving = 0;

    //       Transmit( (unsigned char*)buff,sizeof buff);

           transmitting1= 1;

           while(!(BUTTON_IN & (1<<BUTTON_BIT)));

         }

       }

       else if(!transmitting1)

       {

        ReceiveOn();

         receiving = 1;

       }*/

     }

    }

    void delayms(unsigned int n)

    {

     unsigned int i,j;

     for(i=0;i<n;i++)

     {

       for(j=0;j<800;j++);

     }

    }

    void InitButtonLeds(void)

    {

     // Initialize Port J

     PJOUT = 0x01;

     PJDIR = 0xFF;

     // Set up the button as interruptible

     BUTTON_DIR&=~(1<<BUTTON_BIT);   // 按键设置为输入

     BUTTON_REN|=BIT0;      // 上拉

     // Set up LEDs

     LED_OUT&=~((1<<LED_RBIT)|(1<<LED_GBIT));    // LED端口输出0

     LED_DIR|=(1<<LED_RBIT)|(1<<LED_GBIT);       // LED端口方向设置为输出

    }

    void InitRadio(void)

    {

     // Set the High-Power Mode Request Enable bit so LPM3 can be entered

     // with active radio enabled

     PMMCTL0_H = 0xA5;

     PMMCTL0_L |= PMMHPMRE_L;

     PMMCTL0_H = 0x00;

     WriteRfSettings(&rfSettings);

     WriteSinglePATable(PATABLE_VAL);

    }

    void Transmit(unsigned char *buffer, unsigned char length)

    {

     RF1AIES |= BIT9;                          

     RF1AIFG &= ~BIT9;                         // Clear pending interrupts

     RF1AIE |= BIT9;                           // Enable TX end-of-packet interrupt

     WriteBurstReg(RF_TXFIFOWR, buffer, length);    

     Strobe( RF_STX );                         // Strobe STX  

    }

    void ReceiveOn(void)

    {  

     RF1AIES |= BIT9;                          // Falling edge of RFIFG9

     RF1AIFG &= ~BIT9;                         // Clear a pending interrupt

     RF1AIE  |= BIT9;                          // Enable the interrupt

     // Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode

     Strobe( RF_SRX );                      

    }

    void ReceiveOff(void)

    {

     RF1AIE &= ~BIT9;                          // Disable RX interrupts

     RF1AIFG &= ~BIT9;                         // Clear pending IFG

     // It is possible that ReceiveOff is called while radio is receiving a packet.

     // Therefore, it is necessary to flush the RX FIFO after issuing IDLE strobe

     // such that the RXFIFO is empty prior to receiving a packet.

     Strobe( RF_SIDLE );

     Strobe( RF_SFRX  );                      

    }

    #pragma vector=CC1101_VECTOR

    __interrupt void CC1101_ISR(void)

    {

    static u8 press;

    _DINT();

     switch(__even_in_range(RF1AIV,32))        // Prioritizing Radio Core Interrupt

     {

       case  0: break;                         // No RF core interrupt pending                                            

       case  2: break;                         // RFIFG0

       case  4: break;                         // RFIFG1

       case  6: break;                         // RFIFG2

       case  8: break;                         // RFIFG3

       case 10: break;                         // RFIFG4

       case 12: break;                         // RFIFG5

       case 14: break;                         // RFIFG6          

       case 16: break;                         // RFIFG7

       case 18: break;                         // RFIFG8

       case 20:                                // RFIFG9

    //     if(receiving)    // RX end of packet

    //     {

           // Read the length byte from the FIFO      

           RxBufferLength = ReadSingleReg( RXBYTES );              

           ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength);

           // Stop here to see contents of RxBuffer

           __no_operation();

           press=atoi(RxBuffer);

           if(press==0)

           {

               P1OUT=0x0f;

               P3OUT|=BIT6;

               Unknow_Flg=0;

               Low_Flg=0;

           }

                   else if(press>0&&press<=8)

           {

               P1OUT=0x0f;

               P3OUT&=~BIT6;

               Unknow_Flg=0;

               Low_Flg=0;

           }

                  else if(press>8&&press<=16)

           {

               P1OUT=0x0d;

               P3OUT&=~BIT6;

               Unknow_Flg=0;

               Low_Flg=0;

           }

                  else if(press>16&&press<=24)

           {

               P1OUT=0x05;

              P3OUT&=~BIT6;

              Unknow_Flg=0;

              Low_Flg=0;

           }

                  else if(press>24&&press<=32)

           {

               P1OUT=0x04;

               P3OUT&=~BIT6;

               Unknow_Flg=0;

               Low_Flg=0;

           }

                  else if(press>32&&press<=40)

           {

               P1OUT=0x00;

               P3OUT&=~BIT6;

               Unknow_Flg=0;

               Low_Flg=0;

           }

                  else

                  {

                    Unknow_Flg=1;

                    Low_Flg=0;

                  }

         if(press>=0&&press<=5)

           {

                   Low_Flg=1;

                   Unknow_Flg=0;

           }

           if(RxBuffer[CRC_LQI_IDX] & CRC_OK)

           {                    

             LED_OUT |= (1<<LED_GBIT);         // Toggle LED1

             delayms(10);

             LED_OUT &=~(1<<LED_GBIT);

           }

      //   else while(1);    // trap

         break;

       case 22: break;                         // RFIFG10

       case 24: break;                         // RFIFG11

       case 26: break;                         // RFIFG12

       case 28: break;                         // RFIFG13

       case 30: break;                         // RFIFG14

       case 32: break;                         // RFIFG15

     }  

     ReceiveOn();

     _EINT();

    __bic_SR_register_on_exit(LPM3_bits);    

    }

    这是程序,而且当跑时间长了后会出现

    Wed Jul 18 10:09:09 2012: The stack 'Stack' is filled to 92% (74 bytes used out of 80). The warning threshold is set to 90.%

  • 应该不是,我一直看着数组,后面数组的后面几位一直是0,没有动过,只是一直会出来

    Wed Jul 18 10:09:09 2012: The stack 'Stack' is filled to 92% (74 bytes used out of 80). The warning threshold is set to 90.%

  • 你的stack快满了,运行时有可能stack溢出,需要优化程序结构,比如把数组长度减小,或者修改CMD文件,给stack多分配一些空间

  • 朋友问题解决了吗?

    我也遇到了和你一样的问题,也是进入了 reset_vector  中

    请问你最后怎么解决的!

    谢谢!