AnsweredAssumed Answered

Can not enter timer interrupt wihout debug mode

Question asked by danielc@nexsens.com on Feb 6, 2013
Latest reply on Mar 13, 2013 by AudeR

Hi,

Below is my code, I want use two timers, timer1 for 0.315ms and timer0 for 40s. And timer0 has higher priority than timer1. When I use IAR compiler to debug it by a USB-SWD/UART board, it works fine. But when I just power the board through DVDD and GND pins using two AA batteries. It can not enter timer0.

 

 

Thank you.

 

unsigned int uiSleepTimer = 0;

unsigned int uiHibernateTimer= 0;

unsigned char ucGoToSleep = 0;

unsigned char ucGoToHibernate = 0;

 

//////// Init Part////////////

static void Timer0Init(void);

static void Timer1Init(void);

static void delay(unsigned long);

 

void main()

{

    pADI_WDT ->T3CON = 0;   // Disable watchdog

    DioOen(pADI_GP1,0x38); // Set P1.3 as an output for test purposes

    WdtCfg(T3CON_PRE_DIV1,T3CON_IRQ_EN,T3CON_PD_DIS);

    ClkDis(CLKDIS_DISSPI0CLK|CLKDIS_DISSPI1CLK|CLKDIS_DISPWMCLK|CLKDIS_DISDMACLK);

    ClkCfg(CLK_CD3,CLK_HF,CLKSYSDIV_DIV2EN,CLK_UCLKCG);        // Choose 2MHz for CUP clock

    ClkSel(CLK_CD6,CLK_CD0,CLK_CD0,CLK_CD0);                      // Select CD0 for UART System clock, also for I2C

    NVIC_SetPriority(TIMER0_IRQn,1);

    NVIC_SetPriority(TIMER1_IRQn,2);

    Timer0Init();

    NVIC_EnableIRQ(TIMER0_IRQn);        // Enable Timer1 IRQ

    Timer1Init();

    NVIC_EnableIRQ(TIMER1_IRQn);        // Enable Timer1 IRQ

    while(1)

    {

        if(uiHibernateTimer == 1)

        {

            DioSet(pADI_GP1,0x8);

        }

        else

        {

            DioTgl(pADI_GP1,0x8);

            delay(0x10000);

        }

    }

 

}

void Timer0Init(void)

{

    GptLd(pADI_TM0,40);                                  // Set timeout period for 60 seconds

    GptCfg(pADI_TM0,TCON_CLK_LFOSC,TCON_PRE_DIV32768,TCON_MOD_PERIODIC|TCON_RLD|TCON_ENABLE);

}

//==============================================================================

/**

*    Initialize the timer1

*/

void Timer1Init(void)

{

    GptLd(pADI_TM1,0xFFFE);                //Set timeout period for 0.315ms

    GptCfg(pADI_TM1,TCON_CLK_LFOSC,TCON_PRE_DIV16,TCON_MOD_PERIODIC|TCON_UP|TCON_RLD|TCON_ENABLE);

}

 

//==============================================================================

/**

* A simple delay function

*/

void delay (unsigned long length)

{

   while (length >0)

      length--;

}

////////////////////////////////////////////////////////////////////////////////

//                          Interupt Handler                                  //

////////////////////////////////////////////////////////////////////////////////

void GP_Tmr0_Int_Handler(void)

{

    pADI_TM0->CLRI = 0x01;    // Clear T0 interrupt

    while( (pADI_TM0->STA & 0x01) == 0x01)

    {

        pADI_TM0->CLRI = 0x01;

    }

    DioSet(pADI_GP1,0x8);

    uiHibernateTimer = 1;

}

void GP_Tmr1_Int_Handler(void)

{

    pADI_TM1->CLRI = 0x01;      // Clear T1 interrupt

    while( (pADI_TM1->STA & 0x01) == 0x01)

    {

        pADI_TM1->CLRI = 0x01;

    }

    uiSleepTimer++;

    if(uiSleepTimer > 15780)

    {

        uiSleepTimer = 0;

        DioSet(pADI_GP1,0x8);

        delay(0x3000);

        DioClr(pADI_GP1,0x8);

 

    }

 

}

Outcomes