Currently im working on STM32F103R8 and im trying to create delay using TIM3 ,the following is my code but i didnt get perfect output.Please someone kindly help me to overcome from this.
#include "stm32f10x.h"
void init();
void Timer_delay();
void main()
{
init();
Timer_delay();
while(1)
{
while(TIM3->SR & 0x0001)/*Check the TIM3 update interrupt occurs or not*/
TIM3->SR = 0x0000;/*Remove TIMx update interrupt flag */
GPIOA->BSRR^=0X00000002;
}
}
void init()
{
RCC->APB2ENR=0x00000004;
GPIOA->CRL = 0x00000010;
}
void Timer_delay()
{
//Timer Configuration..//
RCC->APB1ENR = 0X00000002; //Timer3 clock enable..//
TIM3->ARR = 500; //Auto Reload value..//
TIM3->PSC = 64000; //Prescaler value.//
TIM3->CR1= 0X0000; //Clock division & Upcounter mode
//Interrupt Config..//
TIM3->DIER = 0X0001; //Update interrupt Enabled..//
TIM3->CR1= 0X0001; //Counter Enabled..//
}
