Timer doesn't work properly until the external interrupt was triggered.
Hello
I am quite new to microcontroller programming.
and this is my first code with my STM32F429
I write the code with least help of library to learn the basic principle of microcontoller programming.
This is what happened.
I write a program that suppose to turn on/off led every one second(using timer2) or blink the led when I press the button(EXTI0) but my led doesn't turn on/off but Instead keep itseft on(halft brightness) until I press the button and triggered EXTI0 and then everything start working as it supposes to do.
I am pretty sure,It my fault but I still can't figure it out what cause this weird problem.
Here is my code,It's not very clean tho.
#include "stm32f4xx.h"
void digitalWrite(GPIO_TypeDef *GPIOx,uint32_t pinNum,uint32_t state){
if(state)GPIOx->BSRRL |= (1<<pinNum);
else GPIOx->BSRRH |= (1<<pinNum);
}
int main(void)
{
RCC->CFGR &= ~RCC_CFGR_HPRE;
RCC->CFGR &= ~RCC_CFGR_PPRE1;
RCC->CFGR |= (5<<10);
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
RCC->AHB1ENR |= (1<<6);
SYSCFG->EXTICR[1] &= ~(15);
EXTI->IMR |= 1;
EXTI->RTSR |= 1;
TIM3->CNT = 0;
TIM3->PSC = 59999;
TIM3->ARR = 65535;
TIM3->CR1 |= 1;
GPIOG->MODER |= 1<<26;
GPIOG->MODER |= 1<<28;
GPIOG->OTYPER = 0;
GPIOG->OSPEEDR |= 3<<26;
GPIOG->OSPEEDR |= 3<<28;
int i = 0;
TIM3->CR1 |= 1;
NVIC_EnableIRQ(EXTI0_IRQn);
while (1)
{
if(TIM3->CNT>1500){
i^=1;
digitalWrite(GPIOG,14,i);
TIM3->CNT = 1;
}
}
}
void EXTI0_IRQHandler(){
EXTI->PR |= 1;
digitalWrite(GPIOG,14,1);
for(int i = 0;i<50000;i++);
digitalWrite(GPIOG,14,0);
}
uint32_t sEE_TIMEOUT_UserCallback(void)
{
while (1)
{
}
}Thank in advance for your help