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.

Wakeup using timer

Hi all, i'm currently trying to wakeup my tiva from sleep using a timer interrupt. as on now, the interrupt does wake up the tiva board, but it doesn't run the program in my loop the second time it wakes up. below is my timer interrupt function and how i make my board sleep.

// timer intterupt
void Timer0IntHandler(void) {

	UARTprintf("TIMER FIRE\n");
	ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	ROM_IntMasterDisable();

	if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0))
	{
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);
	}
	else
	{
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 1);
	}
	ROM_IntMasterEnable();
}

//sleep function
void uC_Controller_Sleep(void) {

	UARTprintf("System in Sleep Mode\n");

	SysCtlDelay(SysCtlClockGet()/3);

	ROM_SysCtlPeripheralClockGating(true);

	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);

	SysCtlLDOSleepSet(SYSCTL_LDO_0_90V);

	SysCtlSleepPowerSet(SYSCTL_FLASH_LOW_POWER | SYSCTL_SRAM_LOW_POWER);

	SysCtlSleep();
}

while(1) {

	//functions that requires constant running, like data logging etc
	SysCtlDelay(SysCtlClockGet()/3);
	uC_Controller_Sleep();
}

Do need desperate help on this because this is getting frustrating. thanks in advance.

  • Hello Hong,

    It is not clear as to what the configuration of the timer is? It could be possible that it is in One Shot Mode, which would match up the system once only.

    Also it is not clear on the PF0 pin. Please note that PF0 is a NMI pin and needs unlock and commit change. I hope that you have taken care of the same in the main code (though it would not have a bearing on the issue)

    When you connect the debugger, where is the program execution at? Also is there any Bus Fault?

    Lastly the IntMasterDisable and IntMasterEnable is not needed to be done in the interrupt handler.

    Regards

    Amit

  • Hi amit,

    I don't quite get the first point as in to what you mean by oneshot, because i increase the frequency and it seems to be firing continuously, until the board went to sleep the second time round. and no, i didn't receive any bus fault.

    below is the update code of which i changed.

    void Timer0IntHandler(void) {
    
    	ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, 1);
    	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, 0);
    	UARTprintf("TIMER FIRE\n");
    	SysCtlDelay(SysCtlClockGet()/30);
    }
    
    void uC_Controller_Sleep(void) {
    
    	UARTprintf("System in Sleep Mode\n");
    	
    	ROM_SysCtlPeripheralClockGating(true);
    
    	SysCtlLDOSleepSet(SYSCTL_LDO_0_90V);
    	SysCtlSleepPowerSet(SYSCTL_FLASH_LOW_POWER | SYSCTL_SRAM_LOW_POWER);
    
    	SysCtlDelay(SysCtlClockGet()/3);
    
    	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF);
    	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);
    	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
    
    	SysCtlSleep();
    }
    
    //main loop
    while(1) {
    
        //Do some functions here that requires constant running, like data logging etc
        SysCtlDelay(SysCtlClockGet()/3);
        uC_Controller_Sleep();
    }

  • Hello Hong

    Can you please send across the source project, as the code here seems fine (of course it could be optimized). The entirety of the code would be helpful to see why the sleep does not exit second time around.

    Regards

    Amit

  • Hi amit, please find my project file in the attachment. please kindly post a reply once you've downloaded it.

    Updated:

    Hey amit, i found out the problem and got it fixed! i got a loop in my functions that didn't exit. so yeh. thats done. however, i now have this issue of the board seems to reset itself after waking up from sleep on device mode.

  • Hello Hong

    Good to know the first issue has been resolved. Can you please load the updated attachment as it was not present in the last post?

    Regards

    Amit

  • hi amit, everything seems to be working well now. but i've also attached the lastest for your reference. do tell me once you've downloading it.