/** * @brief This function handles COMP interrupt request. * @param None * @retval None */ void COMP1_2_3_IRQHandler(void) { if((EXTI_GetITStatus(EXTI_Line21) != RESET) || (EXTI_GetITStatus(EXTI_Line22) != RESET)) { /* Check input voltage level: within the thresholds, above the upper threshold or under the lower threshold */ InputVoltageLevel_Check(); /* Clear EXTI21 pending bit */ EXTI_ClearITPendingBit(EXTI_Line21); /* Clear EXTI22 pending bit */ EXTI_ClearITPendingBit(EXTI_Line22); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /******************************************************************************* * Common Configuration Routines * *******************************************************************************/ /******* Initialize LEDs available on STM32F091RC-Nucleo RevC board ******************/ BSP_LED_Init(LED2); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /* configure COMP1 and COMP2 with interrupts enabled */ COMP_Config(); /* Check input voltage level: within the thresholds, above the upper threshold or under the lower threshold */ InputVoltageLevel_Check(); /* Infinite loop */ while (1) { if (State == STATE_OVER_THRESHOLD) { /* Restoration done only in case of MCU was in stop mode */ if (EnterInStopMode == 1) { /* Restore config: clock, GPIO... */ SystemClock_Config(); /* Restore GPIO configuration */ BSP_LED_Init(LED2); EnterInStopMode = 0; } /* Turn on LED1 and LED3 and turn off LED2 and LED4 */ while(State == STATE_OVER_THRESHOLD) { /* add your code here */ /* Toggle LED2 */ BSP_LED_Toggle(LED2); HAL_Delay(50); } } else if (State == STATE_WITHIN_THRESHOLD) { /* Turn off LD2 */ BSP_LED_Off(LED2); /* Input voltage is within the thresholds: higher and lower thresholds */ /* Enter STOP mode with regulator in low power */ StopSequence_Config(); } else /* (State == STATE_UNDER_THRESHOLD) */ { /* Restoration done only in case of MCU was in stop mode */ if (EnterInStopMode == 1) { /* Restore config: clock, GPIO... */ SystemClock_Config(); /* Restore GPIO configuration */ BSP_LED_Init(LED2); EnterInStopMode = 0; } /* Turn on LED2 and LED4 and turn off LED1 and LED3 */ while(State == STATE_UNDER_THRESHOLD) { /* add your code here */ /* Toggle LED2 */ BSP_LED_Toggle(LED2); HAL_Delay(1000); } } } }
/** * @brief Comparator callback. * @param hcomp: COMP handle * @retval None */ void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp) { /* Check input voltage level: within the thresholds, */ /* above the upper threshold or under the lower threshold */ InputVoltageLevel_Check(); }