/** * @brief Configures Comparator * @param None * @retval None */ static void COMP_Config(void) { /*##-1- Configure the COMP peripheral ######################################*/ hcomp1.Instance = COMP1; hcomp1.Init.InvertingInput = COMP_INVERTINGINPUT_DAC1; hcomp1.Init.NonInvertingInput = COMP_NONINVERTINGINPUT_IO1; hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; hcomp1.Init.Mode = COMP_MODE_HIGHSPEED; hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLED; hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING_FALLING; if(HAL_COMP_Init(&hcomp1) != HAL_OK) { /* Error */ ErrorHandler(); } /*##-2- Start teh COMP1 and enable the interrupt ###########################*/ if(HAL_COMP_Start(&hcomp1) != HAL_OK) { /* Error */ ErrorHandler(); } }
/** * @brief Enables the interrupt and starts the comparator * @param hcomp: COMP handle * @retval HAL status. */ HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp) { HAL_StatusTypeDef status = HAL_OK; uint32_t extiline = 0; status = HAL_COMP_Start(hcomp); if(status == HAL_OK) { /* Check the parameter */ assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode)); /* Get the Exti Line output configuration */ extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance); /* Configure the rising edge */ /* COMP TriggerMode set to COMP_TRIGGERMODE_IT_RISING or */ /* COMP_TRIGGERMODE_IT_RISING_FALLING. */ if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_RISING) != RESET) { __HAL_COMP_EXTI_RISING_IT_ENABLE(extiline); } else { __HAL_COMP_EXTI_RISING_IT_DISABLE(extiline); } /* Configure the falling edge */ /* COMP TriggerMode set to COMP_TRIGGERMODE_IT_FALLING or */ /* COMP_TRIGGERMODE_IT_RISING_FALLING. */ if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_FALLING) != RESET) { __HAL_COMP_EXTI_FALLING_IT_ENABLE(extiline); } else { __HAL_COMP_EXTI_FALLING_IT_DISABLE(extiline); } /* Enable Exti interrupt mode */ __HAL_COMP_EXTI_ENABLE_IT(extiline); /* Clear COMP Exti pending bit */ __HAL_COMP_EXTI_CLEAR_FLAG(extiline); } return status; }
/** * @brief Enables the interrupt and starts the comparator * @param hcomp: COMP handle * @retval HAL status. */ HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp) { HAL_StatusTypeDef status = HAL_OK; uint32_t extiline = 0; status = HAL_COMP_Start(hcomp); if(status == HAL_OK) { /* Check the parameter */ assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode)); /* Get the Exti Line output configuration */ extiline = COMP_GET_EXTI_LINE(hcomp->Instance); /* Configure the trigger rising edge */ if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_RISING) != RESET) { SET_BIT(EXTI->RTSR, extiline); } else { CLEAR_BIT(EXTI->RTSR, extiline); } /* Configure the trigger falling edge */ if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_FALLING) != RESET) { SET_BIT(EXTI->FTSR, extiline); } else { CLEAR_BIT(EXTI->FTSR, extiline); } /* Clear COMP EXTI pending bit */ WRITE_REG(EXTI->PR, extiline); /* Enable EXTI interrupt mode */ SET_BIT(EXTI->IMR, extiline); } return status; }
/** * @brief Configure COMPx * @param None * @retval None */ static void COMPx_Config(void) { /*##-1- Configure the COMPx peripheral ###################################*/ /* COMPx Init: Inverted Pin is connected to DACx */ /* Non-inverted pin is connected to Humidity Sensor */ CompxHandle.Instance = COMPx; CompxHandle.Init.InvertingInput = COMP_INVERTINGINPUT_DACx; CompxHandle.Init.NonInvertingInput = COMP_NONINVERTINGINPUT_IO1; CompxHandle.Init.Output = COMP_OUTPUT_TIM4IC2; CompxHandle.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; CompxHandle.Init.Hysteresis = COMP_HYSTERESIS_NONE; CompxHandle.Init.BlankingSrce = COMP_BLANKINGSRCE_NONE; CompxHandle.Init.WindowMode = COMP_WINDOWMODE_DISABLED; CompxHandle.Init.TriggerMode = COMP_TRIGGERMODE_NONE; HAL_COMP_Init(&CompxHandle); /*##-2- Start the comparator process #####################################*/ /* Enable COMPx */ HAL_COMP_Start(&CompxHandle); }
/** * @brief Configure COMPx * @param None * @retval None */ static void COMPx_Config(void) { /*##-1- Configure the COMPx peripheral ###################################*/ /* COMPx init: COMPx Output is connected to GPIO only (not redirected */ /* to timers) and output blanking source is connected to */ /* TIM1 OC5. */ CompxHandle.Instance = COMPx; CompxHandle.Init.InvertingInput = COMP_INVERTINGINPUT_VREFINT; CompxHandle.Init.NonInvertingInput = COMP_NONINVERTINGINPUT_IO1; CompxHandle.Init.Output = COMP_OUTPUT_NONE; CompxHandle.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; CompxHandle.Init.BlankingSrce = COMP_BLANKINGSRCE_TIM1OC5; CompxHandle.Init.WindowMode = COMP_WINDOWMODE_DISABLE; CompxHandle.Init.TriggerMode = COMP_TRIGGERMODE_NONE; HAL_COMP_Init(&CompxHandle); /*##-2- Start the comparator process #####################################*/ /* Enable COMPx: the higher threshold is set to VREFINT ~ 1.22 V */ HAL_COMP_Start(&CompxHandle); }