2021-07-24 01:49 PM
How can I make PC 13 blink at a time I set using any timer in stm32f103 using interrupt
(without hal library) ?
2021-07-24 03:08 PM
JW
2021-07-25 03:30 AM
I tried to interrupt the pa3 pin but it didn't work. There is a problem with the interrupt function.
#include "stm32f10x.h" // Device header
int main(void)
{
RCC->APB2ENR |= (1<<2); /// Enabling PORT A
GPIOA->CRL &= 0xFFFF0FFF; /// Reset the pin 3
GPIOA->CRL |= 0x00003000; /// Set PIN 3 as output
__disable_irq();
RCC->APB2ENR|=(1<<11);// timer1 active
TIM2->ARR = 0xffff; // MAX ARR value
TIM2->PSC = 72-1; // 72MHz/72 = 1 MHz ~~ 1 uS delay
TIM2->DIER = 0x1;//enable interrupts upon update (overflow)
TIM2->CR1 = 0x1; // enable timer by setting TIMx_CR1.CEN
NVIC_EnableIRQ(TIM2_IRQn); // tim2_IRQHandler function
__enable_irq();
while(1)
{
}
}
void TIM2_IRQHandler()
{
TIM2->SR =0x01;
GPIOA->ODR ^=0x0008;//toggle pa3
}
2021-07-25 04:23 AM
> TIM2->SR =0x01;
No, you need to write 0 into TIMx_SR.UIF, i.e.
TIM2->SR =~0x01;
JW
2021-07-25 04:43 AM
Thanks ! pa3 pin can blink at exactly 10 hz. I also realized that I set RCC->APB1ENR wrong :p
#include "stm32f10x.h" // Device header
int main(void)
{
RCC->APB2ENR |= (1<<2); /// Enabling PORT A
GPIOA->CRL &= 0xFFFF0FFF; /// Reset the pin 3
GPIOA->CRL |= 0x00003000; /// Set PIN 3 as output
__disable_irq();
RCC->APB1ENR|=(1<<0);// timer2 active
TIM2->ARR = 0xffff; // MAX ARR value
TIM2->PSC = 54; // 10hz frequency
TIM2->DIER = 0x1;//enable interrupts upon update (overflow)
TIM2->CR1 = 0x1; // enable timer by setting TIMx_CR1.CEN
NVIC_EnableIRQ(TIM2_IRQn); // tim2_IRQHandler function
__enable_irq();
while(1)
{
}
}
void TIM2_IRQHandler()
{
TIM2->SR =~0x01;//update interrupt flag
GPIOA->ODR ^=0x0008;//toggle pa3
}