问答

汇集网友智慧,解决技术难题

21ic问答首页 - AT32F421定时器3和15启用中断就进入Infinite_Loop

Infinite 定时器 vi ic IO

AT32F421定时器3和15启用中断就进入Infinite_Loop

abc80512021-10-02


/**
  ******************************************************************************
  * File   : main.c
  * Version: V1.2.4
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "at32f4xx.h"
#include "at32_board.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitType GPIO_InitStructure;
TMR_TimerBaseInitType  TMR_TMReBaseStructure = {0};
TMR_OCInitType  TMR_OCInitStructure = {0};
NVIC_InitType NVIC_InitStructure;

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void AT32_NVIC_Init(void);
void AT32_TMR3_Init(void);

/* Private functions ---------------------------------------------------------*/

int main(void){
  AT32_NVIC_Init();
  RCC_Configuration();

  Delay_init();
  AT32_LEDn_Init(LED3);
  AT32_LEDn_OFF(LED3);

  AT32_TMR3_Init();
  TMR_INTConfig(TMR3, TMR_INT_CC1, ENABLE);


  TMR_Cmd(TMR3, ENABLE);/* TMR3 enable counter */
  while (1){
        Delay_ms(100);
  }
}

void RCC_Configuration(void)
{
        RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR3, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_TMR1, ENABLE);
}

void AT32_NVIC_Init(void){
//        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
        NVIC_InitStructure.NVIC_IRQChannel = TMR3_GLOBAL_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}

/* TMR3 base configuration */
void AT32_TMR3_Init(void){
        TMR_TimeBaseStructInit(&TMR_TMReBaseStructure);
        TMR_TMReBaseStructure.TMR_Period = SystemCoreClock/10000-1;
        TMR_TMReBaseStructure.TMR_DIV = 10000-1;
        TMR_TMReBaseStructure.TMR_ClockDivision = 0;
        TMR_TMReBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
        TMR_TimeBaseInit(TMR3, &TMR_TMReBaseStructure);
}

void TMR3_GLOBAL_IRQHandler(void){
        AT32_LEDn_Toggle(LED3);
        TMR_ClearITPendingBit(TMR3, TMR_INT_Overflow | TMR_INT_CC1 | TMR_INT_CC2 |        TMR_INT_CC3 | TMR_INT_CC4 | TMR_INT_Trigger);
}

回答 +关注 16
5188人浏览 1人回答问题 分享 举报
1 个回答
  • 原厂启动文件问题。
      .word  TMR1_BRK_UP_TRG_COM_IRQHandler      /* TMR1 Break UP TRG COM                       */
      .word  TMR1_CC_IRQHandler                  /* TMR1 Capture Compare                        */
      .word  0
      .word  TMR3_GLOBAL_IRQHandler              /* TMR3

您需要登录后才可以回复 登录 | 注册