Question
Help setting up comparator on STM32G0B1
- December 10, 2024
- 1 reply
- 650 views
Hello,
New to this forum and quite new to STM32 platform, so hi to the community!
I have trouble setting up comparator on board nucleo-stm32G0b1RE. I've been following some tutorials on how to setup through stm32CubeMx, I believe I have the settings right, but I can't make the comparator work, it doesn't trigger the interrupt when I switch the input. Here is what I have so far:
in .ioc file


After code generation, I manually added the callback in main.c:
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
And I believe the interrupt handler was setup allright. The interrupt triggers normally for the ADC (but not for COMP):
/**
* @brief This function handles ADC1, COMP1,COMP2, COMP3 Interrupts (combined with EXTI 17 & 18).
*/
void ADC1_COMP_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_COMP_IRQn 0 */
/* USER CODE END ADC1_COMP_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
HAL_COMP_IRQHandler(&hcomp2);
/* USER CODE BEGIN ADC1_COMP_IRQn 1 */
/* USER CODE END ADC1_COMP_IRQn 1 */
}
You will find attached the whole project, built with cmake under VS code (with stm32 plugin) on windows 11.
