我用的是STM32L151CBT6,现在使用其中的比较器1遇到了问题,请大家帮助一下啊。
STM32L系列单片机比较器基本上雷同于STM32F系列比较器。用分析STM32F的思路就可以的。
问题如下: 使用的PA4 口输入到比较器1的正输入端。软件配置如下,用查询方式是可以正确检测输入端电压的,但是就是进不去比较器中断,请问是怎么回事啊。
void COMP_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//COMP_InitTypeDef COMP_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure PA4 in analog mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;----------------------------------------更改
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);---------------------------------------------更改
/* COMP Peripheral clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP, ENABLE);
COMP_Cmd(ENABLE); /* Enable the Comparator 1 */
Delay(1);
SYSCFG_RISwitchControlModeCmd(ENABLE);/* Enable the switch control mode */
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_VCOMP, ENABLE);/* Close the ADC analog switch VCOMP */
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_CH4, ENABLE); /* Close the I/O analog switch number 4 */----------------------------------------更改
/* Configure and enable EXTI21 */
EXTI_InitStructure.EXTI_Line = EXTI_Line21;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Configure and enable COMP interrupt */
NVIC_InitStructure.NVIC_IRQChannel = COMP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0f;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0f;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
|