Created
November 23, 2012 15:47
-
-
Save boseji/4136201 to your computer and use it in GitHub Desktop.
EFM32 in Energy Mode EM1 for Blinking LEDs using TIMER0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "efm32.h" | |
#include "em_chip.h" | |
#include "em_cmu.h" | |
#include "em_emu.h" | |
#include "em_gpio.h" | |
#include "em_timer.h" | |
#include "em_system.h" | |
void _exit(int code)///New lib SysCall for GCC | |
{ | |
while(1); | |
} | |
void TIMER0_IRQHandler(void) | |
{ | |
/* Clear flag for TIMER0 overflow interrupt */ | |
TIMER_IntClear(TIMER0, TIMER_IF_OF); | |
/* Toggle LED ON/OFF */ | |
GPIO_PinOutToggle(gpioPortE,2); | |
} | |
int main(void) | |
{ | |
// Initialize chip | |
CHIP_Init(); | |
// Enable the External Oscillator and Wati till it stabilizes | |
CMU_OscillatorEnable(cmuOsc_HFXO,true,true); | |
// Set the HFXO as the Clock Source | |
CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); | |
//Disable the HFRCO | |
CMU_OscillatorEnable(cmuOsc_HFRCO, false, false); | |
//Now We are through with setting the clock | |
// So we can Do some GPIO stuff | |
// Prescale the HFPERCLK -> HF/4 = 32/4 = 8Mhz | |
CMU_ClockDivSet(cmuClock_HFPER, cmuClkDiv_4); | |
// Enable clock for GPIO module | |
CMU_ClockEnable(cmuClock_GPIO, true); | |
// Enable clock for TIMER0 module | |
CMU_ClockEnable(cmuClock_TIMER0, true); | |
// Init the LEDs | |
GPIO_PinModeSet(gpioPortE,2,gpioModePushPull,0); | |
//Select TIMER0 parameters | |
TIMER_Init_TypeDef timerInit = | |
{ | |
.enable = true, | |
.debugRun = true, | |
.prescale = timerPrescale1024, | |
.clkSel = timerClkSelHFPerClk, | |
.fallAction = timerInputActionNone, | |
.riseAction = timerInputActionNone, | |
.mode = timerModeUp, | |
.dmaClrAct = false, | |
.quadModeX4 = false, | |
.oneShot = false, | |
.sync = false, | |
}; | |
// Enable overflow interrupt | |
TIMER_IntEnable(TIMER0, TIMER_IF_OF); | |
// Enable TIMER0 interrupt vector in NVIC | |
NVIC_EnableIRQ(TIMER0_IRQn); | |
// Set TIMER Top value - Top Value / (8MHz / 1024 (prescaler)) | |
// For 2 Seconds Top Value= 15625 | |
TIMER_TopSet(TIMER0, 15625); | |
/* Configure TIMER */ | |
TIMER_Init(TIMER0, &timerInit); | |
while(1) | |
{ | |
//We Sleep even if we wake up from the interrupt | |
EMU_EnterEM1(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment