G4
COMP_HandleTypeDef hcomp1;
void COMP1_Init(void)
{
hcomp1.Instance = COMP1;
hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO1; // 比较器[+]输入端,连接外部GPIO
hcomp1.Init.InputMinus = COMP_INPUT_MINUS_DAC1_CH1; // 比较器[-]输入端,连接内部 DAC1 通道1
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; // 输出极性:非反向([+] > [-] 输出高电平)
hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE; // 不设置迟滞
hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE; // 不屏蔽输出结果
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE; // 不触发中断
if (HAL_COMP_Init(&hcomp1) != HAL_OK)
{
while (1) ;
}
}
// 启动比较器
HAL_COMP_Start(&hcomp1);
// 启动比较器(如果设置了触发中断)
HAL_COMP_Start_IT(&hcomp1);