EFM32之CMU

此程序是配置EFM32的时钟频率,用OUTPUT_INTERNAL和OUTPUT_EXTERNAL来区分是内部时钟和外部时钟。    

通过用示波器测量PA1脚和PA2脚的频率,证明程序完全正确。

#include <stdint.h>
#include <stdbool.h>
#include "efm32.h"
#include "efm32_chip.h"
#include "efm32_cmu.h"
#include "efm32_gpio.h"

#define OUTPUT_INTERNAL      1      //GPIO输出内部振荡波形
//#define OUTPUT_EXTERNAL      2    //GPIO输出外部晶振波形

int main(void)
{
  /* Chip errata */
  CHIP_Init();

#ifdef OUTPUT_INTERNAL
  CMU_HFRCOBandSet(cmuHFRCOBand_1MHz);
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);//1MHz
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);//32KHz
#elif defined OUTPUT_EXTERNAL
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);//32MHz
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);//32KHz
#endif

  CMU_ClockEnable(cmuClock_GPIO,true);  //使能GPIO模块
  GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 1);  //将相应的GPIO口设置成输出,低频
  GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 1);  //将相应的GPIO口设置成输出,高频
  
#ifdef OUTPUT_INTERNAL
  CMU->CTRL |= CMU_CTRL_CLKOUTSEL0_HFRCO + CMU_CTRL_CLKOUTSEL1_LFRCO;//CMU_CTRL_CLKOUTSEL0_HFXO; //配置为HFRCO输出
#elif defined OUTPUT_EXTERNAL
  CMU->CTRL |= CMU_CTRL_CLKOUTSEL0_HFXO + CMU_CTRL_CLKOUTSEL1_LFXO;
#endif
  

  //允许GPIO的复用功能,并且置位允许位
  CMU->ROUTE = CMU_ROUTE_CLKOUT0PEN | CMU_ROUTE_CLKOUT1PEN | CMU_ROUTE_LOCATION_LOC0;      


  while (1)
  {
      
  }
}

 

posted @ 2013-03-28 22:30  zpehome  阅读(1216)  评论(0编辑  收藏  举报