how to initialize timers in stm32f103r8? does providing HSE is compulsary?
i want to create a delay function using timer TIM1 or TIM2 , after completely reading the datasheet i cannot initialize delay does it requires any external input?
i have attached my sample code
#include "stm32f10x.h"
void delay();
int main()
{
/*Initialising Clock*/
RCC->CR = 0x00000103; //HSI Enable
RCC->CFGR = 0x051C0000; //HSI clock selected
RCC->CR = 0x01000103; //PLL enabled
RCC->AHBENR = 0x0001D057; //Clock Enable
RCC->APB2ENR = 0x00005E7D; //Clock Enable
RCC->APB1ENR = 0x3E7EC83F; //Clock Enable
RCC->CSR = 0x0C000001; //LSI Enabled
/* Initialising GPIO */
GPIOA->CRL = 0x11111111;
GPIOA->CRH = 0x11111111;
GPIOB->CRL = 0x11111111;
GPIOB->CRH = 0x11111111;
GPIOC->CRL = 0x11111111;
GPIOC->CRH = 0x11111111;
GPIOD->CRL = 0x11111111;
GPIOD->CRH = 0x11111111;
while (1)
{
GPIOA->ODR = 0x0000FFFF;
GPIOB->ODR = 0x0000FFFF;
GPIOC->ODR = 0x0000FFFF;
GPIOD->ODR = 0x0000FFFF;
delay();
GPIOA->ODR = 0x00000000;
GPIOB->ODR = 0x00000000;
GPIOC->ODR = 0x0000FFFF;
GPIOD->ODR = 0x0000FFFF;
delay();
}
}
void delay()
{
TIM2->CR1 = 0x0001; //Counter Enabled
TIM2->EGR = 0x0041; //Trigger generation & update generation enabled
TIM2->CNT = 0xFFFF; //Counter value set
TIM2->PSC = 0X0001; //Prescalar value set
TIM2->ARR = 0xFFFF; //Auto - Reload register set
}