Question
TIMERS used as DELAY Function For Beginners on STM32F3
Posted on December 19, 2013 at 13:28
Function works for TIM6 basic timer used as delay on STM32F303 , with suitable modifications can work on any STM8,32 variants
void TIMER_DELAY(uint16_t value){RCC->APB1ENR |= RCC_APB1Periph;
//value is 0x10 TIM6->ARR = value; // delay in ms TIM6->PSC = 36000-1; // APB1 = 36Mhz so eqn : CLK_CNT = (36000000)/36000,i.e. CLK_CNT = 1Khz TIM6->CR1 = 0x01; // ENaBle TIMER while(!((TIM6->SR & 0x01) == 0x01)); // Check for Update Event TIM6->CR1 &= ~(0x01); // Disable timer TIM6->SR &= ~(0x01); // Reset the update event}For eg. TIMER_DELAY(100) would provide me 100ms delay. #old-school-delay-loops