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.

EK-LM4F120XL: Repeated hibernation does not take place after a while

Part Number: EK-LM4F120XL

Hello,

I'm trying to achieve a simple functionality on my EK-LM4F120XL. Basically, the device has to go in a hibernation loop, and at the times it wakes up, it's supposed to light the blue red and post the current temperature value from the processor's sensor to UART. With the code below, the functionality I described works for an uncertain amount of times but then it halts. No LED lighting up, or no output from UART side. I'd be really glad if you can take a look at my code and tell me what am I missing. Thanks!

#include <stdint.h>
#include <stdbool.h>
#include "utils/ustdlib.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/debug.h"
#include "driverlib/hibernate.h"
#include "driverlib/gpio.h"
#include "utils/uartstdio.h"
#include "driverlib/uart.h"
#include "driverlib/fpu.h"
#include "driverlib/adc.h"

void
ConfigureUART(void)
{
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable UART0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure GPIO Pins for UART mode.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Use the internal 16MHz oscillator as the UART clock source.
    //
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(0, 115200, 16000000);
}

int main(void)
{
	  uint32_t ui32ADC0Value[4];
    volatile uint32_t ui32TempAvg;
    volatile uint32_t ui32TempValueC;
    volatile uint32_t ui32TempValueF;
	
	  SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
	  
	  if(HibernateIsActive()) {
				HibernateGPIORetentionDisable();
		}
		FPULazyStackingEnable();
		
		SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
		
		HibernateEnableExpClk(SysCtlClockGet());
		HibernateGPIORetentionEnable();
	  HibernateRTCEnable();
		HibernateRTCSet(0);
		HibernateRTCMatchSet(0,5);
		HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
		
		GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
		
		// Added
		SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
 
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 1);
		// End added
		
		//
    // Initialize the UART.
    //
    ConfigureUART();
		
    //
    // Hello!
    //
    //UARTprintf("Hello, world!\n");
		
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

        //
        // Delay for a bit.
        //
    //SysCtlDelay(SysCtlClockGet() / 10 / 3);

        //
        // Turn off the BLUE LED.
        //
    //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

        //
        // Delay for a bit.
        //
    //SysCtlDelay(SysCtlClockGet() / 10 / 3);

			  // Added
		ADCIntClear(ADC0_BASE, 1);
    ADCProcessorTrigger(ADC0_BASE, 1);
 
		while(!ADCIntStatus(ADC0_BASE, 1, false))
		{
		}
	 
		ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
		ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
		ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
		ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
		UARTprintf("%u \n", ui32TempValueC);
		UARTDisable(UART0_BASE);
		SysCtlDelay(26666666);
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
			  // Added end

	HibernateRequest();
	while(1)
	{
	}
}