2024-12-09 11:23 PM
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.
2024-12-10 02:37 AM
I don't use Cube/HAL, but you don't appear to have the COMP interrupt enabled anywhere, both at the peripheral level (and note, that COMPs are different from many other peripherals in that their interrupts go through EXTI, so you have to enable it there) and in NVIC.
Maybe there are clicking setups for these in CubeMX too.
JW