求助 STM8L152 内部比较器怎么用
本帖最后由 牧雲丶風临晚 于 2015-12-15 13:26 编辑voidComp2_Init()
{
COMP_DeInit();
COMP_Init(COMP_InvertingInput_IO,COMP_OutputSelect_TIM2IC2,COMP_Speed_Fast);
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_4,ENABLE); //反相输入端配置 PC7
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_5,ENABLE); //反相输入端配置 PC4
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_6,ENABLE); //反相输入端配置 PC3
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_24,ENABLE); //正相输入端配置PE5
COMP_SchmittTriggerCmd(DISABLE);
COMP_EdgeConfig(COMP_Selection_COMP2,COMP_Edge_Rising_Falling); //边沿触发
COMP_ITConfig(COMP_Selection_COMP2,ENABLE); //中断使能
}
INTERRUPT_HANDLER(TIM2_CC_USART2_RX_IRQHandler,20)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
u8 i=0;
if(COMP_GetITStatus(COMP_Selection_COMP2)==SET)
{
}
COMP_ClearITPendingBit(COMP_Selection_COMP2);
}
进不去中断啊
打算 三路负输入 分别跟正输入比较 负端比正端电压高产生中断
本帖最后由 牧雲丶風临晚 于 2015-12-15 16:18 编辑
STM8L系列 部分芯片是没有DMA COMP的 大家选型的时候一定要注意啊。
分享下使用的心得,当做个笔记吧
1、配置IO口为浮空输入无中断模式;
2、首先 初始化comp的时候 同样要开时钟,有时候在接触陌生的东西时候,会忘掉最基本的
3、用COMP_Init();初始化函数,设置比较器输入端,输出端(没用到),速度;
4、SYSCFG_RIIOSwitchConfig();配置相对应的输入口;
5、COMP_EdgeConfig(); 配置触发
6、COMP_ITConfig();最后开中断
中断函数:
INTERRUPT_HANDLER(ADC1_COMP_IRQHandler,18)
{
}
经过别人指导解决这个问题了。
我在使用比较器1的时候,在没进入休眠之前,可以触发中断,可以读取比较器输出结果。一旦进入halt就唤醒不了了,或者是一直产生中断,不知道是哪里弄错了。有大神帮忙分析下吗?
GPIO_Init(GPIOA,GPIO_Pin_5,GPIO_Mode_In_FL_No_IT);
static void COMP_Config(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE);
/* Connect internal reference voltage to COMP1 inverting input */
COMP_VrefintToCOMP1Connect(ENABLE);
/* close the analog switch number 0 */
SYSCFG_RIAnalogSwitchConfig(RI_AnalogSwitch_0, ENABLE);
/* close the analog switch number 1 */
SYSCFG_RIAnalogSwitchConfig(RI_AnalogSwitch_14, ENABLE);
/* close the I/O switch number 2 */
SYSCFG_RIIOSwitchConfig(RI_IOSwitch_2, ENABLE);// PA5
COMP_EdgeConfig(COMP_Selection_COMP1, COMP_Edge_Rising);
/* Enable COMP1 Interrupt */
COMP_ITConfig(COMP_Selection_COMP1, ENABLE);
/* Configure the event detection */
}
INTERRUPT_HANDLER(ADC1_COMP_IRQHandler,18)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
COMP_ClearITPendingBit(COMP_Selection_COMP1);
}
页:
[1]