STM32F4 TIMER INTERRUPT NOT HAPPENİNG
Hı everyone, ı was trying to design basic timer project in register level about toggling on related led pin every 1 second. However, the led is on a few seconds after that it is off and never becoming on. When ı do the same project in HAL library, it worked well. By the way, I use APB1 as 84 MHz. Is there anything i missed out ?
/* Includes */
#include "stm32f4xx.h"
#include "stm32f4_discovery.h"
void RCC_Config()
{
RCC->CR |= 0x00030000; // HSEON and HSEONRDY enable
while(!(RCC->CR & 0x00020000)); // HSEON Ready Flag wait
RCC->CR |= 0x00080000; // CSS Enable
RCC->CR |= 0x01000000; // PLL ON
RCC->PLLCFGR |= 0x00400000; // PLL e HSE seçtik
RCC->PLLCFGR |= 0x00000004; // PLL M = 4
RCC->PLLCFGR |= 0x00005A00; // Pll N = 168
RCC->PLLCFGR |= 0x00000000; // PLL p = 2
RCC->CFGR |= 0x00000000; // AHB Prescaler = 1
RCC->CFGR |= 0x00080000; // APB2 Prescaler = 2
RCC->CFGR |= 0x00001400; // APB1 Prescaler = 4
RCC->CIR |= 0x00080000; // HSERDY Flag clear
RCC->CIR |= 0x00800000; // CSS Flag clear
}
void GPIO_Config()
{
RCC->AHB1ENR |= 0x00000008; // GPIOD active
GPIOD -> MODER |= 0x55000000; // 12-13-14-15 output
GPIOD->PUPDR = 0x00000000; // no pull-up, pull-down
}
void TIM_Config()
{
RCC->APB1ENR |= 1 << 0; // TIM2 clock enable
TIM2->CR1 |= 0 << 4; // Counter mode is upcounter (DIR)
TIM2->CR1 |= 0 << 5; // Center aligned mode edge-aligned mode (CMS)
TIM2->CR1 |= 0 << 8; // Set the clock divisixon to 1 (CKD)
//TIM2->CR1 |= 1 << 2; // only under ve overflow generate interrupt
TIM2->SMCR |= 0 << 0; // Internal clock source (SMS)
TIM2->EGR |= 1 << 0; // Tımer Update Generation ( UG: Update generation)
TIM2->DIER |= (1 << 0);
TIM2->PSC |= 41999; // 84000 MHz / (41999+1) = 2000 ( PSC[15:0]: Prescaler value) -> The counter clock frequency CK_CNT is equal to fCK_PSC / (PSC[15:0] + 1)
TIM2->ARR |= 1999; // 2000/2000 = 1 saniye => 1 saniyede bir 2000 (ARR=autoreload değeri) saydirmis oluruz.
//TIM2->CR1 &= ~(1<<0); // Tımer2 Counter Disable for now (CEN:Counter enable)
TIM2->CR1 |= (1<<0); //
}
void EXTI_Config()
{
NVIC_EnableIRQ(TIM2_IRQn);
}
void TIM2_IRQHandler(void)
{
if(TIM2->SR & (1<<0))
{
TIM2->SR &= ~(1<<0);
GPIOD->ODR ^= (1 << 12);
}
}
int main(void)
{
RCC_Config();
GPIO_Config();
TIM_Config();
EXTI_Config();
while (1)
{
}
}
void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size){
/* TODO, implement your code here */
return;
}
uint16_t EVAL_AUDIO_GetSampleCallBack(void){
/* TODO, implement your code here */
return -1;
}
