crc1010 发表于 2022-8-25 13:55

我在官方COMP例程上添加中断,寄存器都正常死活进不去中断函数

    COMP_InitType COMP_Initial;

    /*Set dac2,dac1. because dac1/PA4 is share pin line,so only PB0 puls 0/1, can find out puls*/
    COMP_SetRefScl(16, true, 32, true);
    /*Initial comp*/
    COMP_StructInit(&COMP_Initial);
    COMP_Initial.InpSel   = COMP1_CTRL_INPSEL_PB10;
    COMP_Initial.InmSel   = COMP1_CTRL_INMSEL_PA5;
    COMP_Initial.SampWindow = 18;       //(0~31)
    COMP_Initial.Thresh   = 12;       //Thresh should be greater than half of SampWindow and should be less than SampWindow at the same time.
    COMP_Init(COMP1, &COMP_Initial);
    COMP_Enable(COMP1, ENABLE);
   
    EXTI_InitType EXTI_InitStructure;
    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_InitPeripheral(&EXTI_InitStructure);
   
    NVIC_InitType NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel                   = COMP_1_2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority      = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    EXTI_ClrITPendBit(EXTI_LINE21);
    NVIC_ClearPendingIRQ(COMP_1_2_IRQn);
    COMP_SetIntEn(ENABLE);

Afanx 发表于 2022-8-25 15:40

检查一下COMP的输出功能是否正常,寄存器的OUT位能否正常翻转,还有中断入口函数COMP_1_2_IRQHandler是否正确。

sy12138 发表于 2022-8-25 17:53

可以发一下GPIO、时钟配置和中断服务函数

xch 发表于 2022-8-26 13:26

是不是GPIO没配置成模拟功能?

crc1010 发表于 2022-8-26 17:14

害 ,中断函数少打了个字母,浪费一天时间,写代码时一点要注意
页: [1]
查看完整版本: 我在官方COMP例程上添加中断,寄存器都正常死活进不去中断函数