Answer the question
In order to leave comments, you need to log in
How to make stm32 smart delay before execution?
There are such cases, some devices require a delay between different commands, for example, wait 300ms, arduino people are used to simple while(cnt--) loops, but this does not suit me, so the question is how to organize a delay with a timer?
Here is the code I posted:
#include "Delay.h"
static uint8_t flag = 1;
void delay(uint32_t _delay){
initTIM6();
TIM6->ARR = _delay;
TIM6->CR1 |= TIM_CR1_CEN;
flag = 1;
while(flag);
}
void TIM6_IRQHandler(void){
flag = 0;
TIM6->CR1 &= ~TIM_CR1_CEN;
TIM6->SR &= ~TIM_SR_UIF;
}
void initTIM6(){
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
TIM6->PSC = SystemCoreClock / 1000 - 1;
TIM6->DIER |= TIM_DIER_UIE;
NVIC_EnableIRQ(TIM6_IRQn);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question