查看: 4636|回复: 1
打印 上一主题 下一主题

STM32初始化进入HardFault_Handler

[复制链接]
跳转到指定楼层
沙发
发表于 2016-6-22 18:54:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
执行完NVIC_Configuration();就进去了,中断函数无法打断点,说明根本不会执行到it.c里面,贴代码:(ps:不会是数组越界之类的,整个工程只有初始化和定时器中断)
void main()
{
#ifdef DEBUG
  debug();
#endif
    __disable_interrupt();
   Hardware_initial();
   __enable_interrupt();
    while(1)
   {
}
}
void Hardware_initial()
{
  /* System Clocks Configuration */
  RCC_Configuration();
  
  /* NVIC configuration */
  NVIC_Configuration();
   /*TIM2  Configuration */
   TIM2_Configuration();
}
RCC_Configuration();中开启了GPIO和TIM2的时钟。
void NVIC_Configuration(void)//»¹ÐèÒªµ÷ÕûÓÅÏȼ¶ÎÊÌâ
{
#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
  
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* Configure the NVIC Preemption Priority Bits */  
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  
  /* Enable the TIM2 gloabal Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
}
void TIM2_Configuration(void)
{
   TIM_DeInit(TIM2);
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
                                         
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  /* Prescaler configuration */
  TIM_PrescalerConfig(TIM2, 71, TIM_PSCReloadMode_Immediate);//ʱÖÓƵÂÊ=72M/(ʱÖÓÔ¤·ÖƵֵ+1)=1M

  TIM_OCInitTypeDef  TIM_OCInitStructure;
  /* PWM2 Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;//TIMx_CNT>TIMx_CCR1ʱͨµÀÒ»Êä³öÓÐЧµçƽ
  //TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 3000;
  //TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC1Init(TIM2, &TIM_OCInitStructure);

  TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);//????
  TIM_ITConfig(TIM2,TIM_IT_CC1,ENABLE);//set interrupt
   
  /* TIM2 enable counter */
   TIM_Cmd(TIM2, ENABLE);//CR1

}
it.c里面:
void TIM2_IRQHandler(void)
{
  u16 capture;
  if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
  {
    TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
    capture=TIM_GetCounter(TIM2);
    TIM_SetCompare1(TIM2, capture + 400);
    flag=1;
  }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入中科因仑

本版积分规则

快速回复 返回顶部 返回列表