现使用N32G430的低功耗定时器的编码器模式,计数没有任何问题,但是我想在计数器达到重装载值时触发中断,但是这个中断一直触发不了。这个是怎么回事。
- void EncInputIoConfig(void)
- {
- GPIO_InitType GPIO_InitStructure;
- GPIO_Structure_Initialize(&GPIO_InitStructure);
- /* Enable the GPIO Clock */
- RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOB);
- /* Configure the GPIO pin */
- GPIO_InitStructure.Pin = GPIO_PIN_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
- GPIO_InitStructure.GPIO_Alternate = GPIO_AF3_LPTIM;
- GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
- /* Configure the GPIOpin */
- GPIO_InitStructure.Pin = GPIO_PIN_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
- GPIO_InitStructure.GPIO_Alternate = GPIO_AF6_LPTIM;
- GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
- }
- void LPTIMNVIC_Config(FunctionalState Cmd)
- {
- EXTI_InitType EXTI_InitStructure;
- NVIC_InitType NVIC_InitStructure;
- EXTI_Flag_Status_Clear(EXTI_LINE20);
- EXTI_InitStructure.EXTI_Line = EXTI_LINE20;
- #ifdef __TEST_SEVONPEND_WFE_NVIC_DIS__
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
- #else
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- #endif
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Peripheral_Initializes(&EXTI_InitStructure);
- /* Enable the RTC Alarm Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = LPTIM_WKUP_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PER_PRIORITY_1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_SUB_PRIORITY_1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = Cmd;
- NVIC_Initializes(&NVIC_InitStructure);
- }
- void Lptim_EncInit(void)
- {
- RCC_LPTIM_Enable();
- RCC_LSI_Enable();
- while(RCC_LSI_Stable_Wait() != SUCCESS);
- RCC_LPTIM_Clock_Config(RCC_LPTIMCLK_SRC_LSI);
- LPTIMNVIC_Config(ENABLE);
-
- LPTIM_Prescaler_Set(LPTIM,LPTIM_PRESCALER_DIV1);
- /* Config LPTIM */
- EncInputIoConfig();
-
- LPTIM_Clock_Source_Set(LPTIM,LPTIM_CLK_SOURCE_INTERNAL);
- LPTIM->CFG &=~(LPTIM_CFG_NENC|LPTIM_CFG_ENC);
- LPTIM_Encoder_Mode_Enable(LPTIM);
- /* ENC MODE1 */
- LPTIM_Encoder_Mode_Set(LPTIM,LPTIM_ENCODER_MODE_RISING_FALLING);
- LPTIM_ON(LPTIM);
- LPTIM_Auto_Reload_Set(LPTIM,65535);
- LPTIM_Compare_Set(LPTIM,10000);
- LPTIM_Counter_Start(LPTIM,LPTIM_OPERATING_MODE_CONTINUOUS);
- LPTIM_Interrupt_Enable(LPTIM,LPTIM_INT_ARRMIE);
- }
- void LPTIM_WKUP_IRQHandler(void)
- {
- if (LPTIM_Flag_Get(LPTIM, LPTIM_INTSTS_FLAG_ARRM) != RESET)
- {
- LPTIM_FLAG_Clear(LPTIM, LPTIM_INTSTS_FLAG_ARRM);
- EXTI_Flag_Status_Clear(EXTI_LINE20);
- }
- }
测试在计数到达65535时不会触发中断
|