I'm using a TM4C123GH6PM.
I'm trying to get a sleep mode working for my project. The idea is the MCU will go into sleep mode and wake up about 30 times a second to check various states and see if a power up is required. I've managed to enter sleep mode and set up a timer, the problem is, as soon as my first timer interrupt arrives, the MCU wakes up again.
If I disable my timer, the MCU remains in sleep mode, but of course I can't do what I need to decide if the MCU should power up.
I've tried adding a SysCtlSleep() call to the end of my timer ISR - but this just results in the timer firing once then stopping... I think that an exception may be occurring but I'm not certain.
I've read up on SLEEPEXIT bit in the SYSCTRL register, however, short of writing the bit directly, which seems potentially unwise (without the API knowing it is set), I cannot find a way to control this. I'm not sure if this will help either, as the documentation seems to mention it applying only to exceptions rather than conventional interrupts.
Code for my Timer ISR and sleep routines below.
void Timer0BIntHandler(void) { // clear IF flag TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // blink LED gpio_led_ctrl(0, 1); delay(200); gpio_led_ctrl(0, 0); delay(200); return; } void mcu_zzz() { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); // Approx 30Hz heartbeat TimerPrescaleSet(TIMER0_BASE, TIMER_B, 170); TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000); IntMasterEnable(); TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); IntEnable(INT_TIMER0B); // Processor wakes up if this is enabled, remains in sleep if disabled but ISR will of course not fire TimerEnable(TIMER0_BASE, TIMER_B); SysCtlPeripheralClockGating(1); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); SysCtlSleep(); }
Any help appreciated.