How to call timer interrupt using registers? [NO HAL DRIVERS]
Hi, i am trying to call timer interrupt handler using registers and the following is my code, but the problem is that the function is being not called, I see no output in the oscilloscope or live expression. First my DAC value is still 0, the counter is running though. I also tried to use toggle breakpoint to see where the problem lies and I think it's at this point // Clear the interrupt flag
TIM2->SR &= ~TIM_SR_UIF;
but i am not sure. Could anyone confirm if what i am doing is correct/wrong?
Btw, i am using stm32-g071rb.
int main(){
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_DAC1_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
// TIM2->DIER |= TIM_DIER_UIE; // Enable the update (overflow) interrupt
NVIC_SetPriority(TIM2_IRQn, 0); // Set the interrupt priority (if needed)}
NVIC_EnableIRQ(TIM2_IRQn); // Enable the timer interrupt in the NVIC
TIM2->CR1 |= TIM_CR1_CEN; // Start the timer
}
void TIM2_IRQHandler(void)
{
/* USER CODE BEGIN TIM2_IRQn 0 */
if (TIM2->SR & TIM_SR_UIF)
{
// Timer interrupt flag is set, do something here
DAC1->DHR12L2 = 1;
HAL_Delay(100);
//
// Clear the interrupt flag
TIM2->SR &= ~TIM_SR_UIF;
}
/* USER CODE END TIM2_IRQn 0 */
HAL_TIM_IRQHandler(&htim2);
/* USER CODE BEGIN TIM2_IRQn 1 */
/* USER CODE END TIM2_IRQn 1 */
}
