2019-09-18 09:44 PM
I have tried below code for generating the microsecond delay for the stm32l0, but its not working.
int myTicks = 0;
********
//Enabling The timerr
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->PSC = 0;
TIM2->ARR = 72;
TIM2->CR1 |= TIM_CR1_URS;
TIM2->DIER |= TIM_DIER_UIE;
TIM2->EGR |= TIM_EGR_UG;
// TIM2->CR1 |= TIM_CR1_CEN;
// NVIC_SetPriority(TIM2_IRQn,0x03);
NVIC_EnableIRQ(TIM2_IRQn);
********
void dUs(int us)
{
TIM2->CR1 |= TIM_CR1_CEN;
myTicks = 0;
while(myTicks<us);
TIM2->CR1 &= ~TIM_CR1_CEN;
}
*******
void TIM2_IRQ_handler(void)
{
if (TIM2->SR & TIM_SR_UIF) {
TIM2->SR &= ~(TIM_SR_UIF);
myTicks++;
}
}
2019-09-18 10:08 PM
Don't use 1 MHz interrupts. Watch the counter count instead.
Set ARR to 0xFFFF and PSC = CPUMHZ-1
2019-09-19 01:57 AM
my system clock is 8Mhz and I want to generate the 1 microsecond delay.
What should be ARR and PSC ?