|
我现在要用外部时钟来工作,但是执行切换工作。去测晶振没有时钟信号。大家帮我看看那里有问题。代码如下:
void InitializeCLK(void)
{ ///这段代码也是在这里看到的移用
ErrorStatus status = 0;
CLK_DeInit();
//高速内部时钟/CPU分频系数设置
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
//时钟源选择设置
status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, \
CLK_SOURCE_HSE, DISABLE, DISABLE);
CLK_ClockSwitchCmd(ENABLE);
while (status == 0);
CLK_ClockSwitchCmd(DISABLE);
}
/**
* @brief Example firmware main entry point.
* @par Parameters:
* None
* @retval void None
* @par Required preconditions:
* None
*/
void main(void)
{
u16 i;
for(i=0;i<1000;i++)
{
nop();
}
InitializeCLK(); ///主要就是调用这个进行切换
/* TIM1 Peripheral Configuration */
TIM1_DeInit();
/* Time Base configuration */
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 1000, 0);//4095
/* Channel 1, 2 and 3 Configuration in TIMING mode */
/* TIM1_Pulse = 2047 */
TIM1_OC1Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 2047, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
/* TIM1_Pulse = 1023 */
TIM1_OC2Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 1023, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
/* TIM1_Pulse = 511 */
TIM1_OC3Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 511, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM1_BDTRConfig( TIM1_OSSISTATE_ENABLE, TIM1_LOCKLEVEL_OFF, 1, TIM1_BREAK_DISABLE, TIM1_BREAKPOLARITY_LOW, TIM1_AUTOMATICOUTPUT_ENABLE);
TIM1_CCPreloadControl(ENABLE);
TIM1_ITConfig(TIM1_IT_COM, ENABLE);
/* TIM1 counter enable */
TIM1_Cmd(ENABLE);
/* TIM4 Peripheral Configuration */
/* Time Base configuration */
TIM4_TimeBaseInit(TIM4_PRESCALER_128, 0xFF);
/*TIM4 counter enable */
TIM4_Cmd(ENABLE);
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
/* Main Output Enable */
TIM1_CtrlPWMOutputs(ENABLE);
enableInterrupts();
while (1);
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|