Hi there, I am very new in programming micro.I am using stm32f100 discovery board and made a small code to turn the stm board led on for 5 second once hit the user push button.then the led goes off.The partial code below I have to do the work.The program runs my led on for 5 sec only the first time I hit the user button.But next time I hit user it gives me 4 sec, and keep changing everytime to 3s,4s,,like random.I could not figure out what I am doing wrong.Could anyone please help me on this.Thanks in advance.
TIM3->PSC = 23999; // Set prescaler to 24 000 (PSC + 1) TIM3->ARR = 5000; // Auto reload value 1000 while(1) { if(GPIOA->IDR & (1 << 0)) //if user ush button is set { TIM3->CR1 = TIM_CR1_CEN;//enable timer3 TIM3->SR &= ~TIM_SR_UIF;// clear uif bit while (1) { GPIOC->BSRR = (1 << 8); //until UIF flag is not set led 4(pc8) in stm board blinks if(TIM3->SR & TIM_SR_UIF) // if UIF flag is set { GPIOC->BRR = (1 << 8); //clear the pc8 break; } } } }
@Bradford,sorry about that.Next time I will use tab instead the space bar.Thanks for the suggestion.
No, Bradford didn't talk about use of tab key contra space key. Just that if you use the tab key to indent, you should configure the editor to convert indents into a sequence of spaces. Because source code that contains the tab character will expand differently depending on where you post it, or which editor you open the source code in.