cancel
Showing results for 
Search instead for 
Did you mean: 

Currently im working on STM32F103R8 and im trying to create delay using TIM3 ,the following is my code but i didnt get perfect output.Please someone kindly help me to overcome from this.

Sm.16
Associate II

#include "stm32f10x.h"

void init();

void Timer_delay();

void main()

{

 init();

 Timer_delay();

 while(1)

 {

  while(TIM3->SR & 0x0001)/*Check the TIM3 update interrupt occurs or not*/

  TIM3->SR = 0x0000;/*Remove TIMx update interrupt flag */  

 GPIOA->BSRR^=0X00000002;

  

 }

}

void init()

{

 RCC->APB2ENR=0x00000004;

 GPIOA->CRL = 0x00000010;

}

void Timer_delay()

{

 //Timer Configuration..//

RCC->APB1ENR = 0X00000002; //Timer3 clock enable..//

     

TIM3->ARR = 500; //Auto Reload value..//

TIM3->PSC = 64000; //Prescaler value.//

    TIM3->CR1= 0X0000; //Clock division & Upcounter mode

//Interrupt Config..//

    TIM3->DIER = 0X0001; //Update interrupt Enabled..//

   TIM3->CR1= 0X0001; //Counter Enabled..//

7 REPLIES 7

> GPIOA->BSRR^=0X00000002;

As BSRR is a write-only register and reads always as 0, this is effectively the same as

GPIOA->BSRR=0X00000002;

which always only sets PA1.

JW

Try GPIOA->ODR ^=0x0002; // Toggle PA1

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Sm.16
Associate II

yes! i got no errors,but unfortunately i'm unable to get an output in proteus simulation.

Sm.16
Associate II

as far now im not getting any errors or warning in my program,but while simulating in proteus im not getting the output as per the program.Below is my proteus connection.Kindly 0690X000008wLZnQAM.pnghelp me to overcome from this.

Would this be a real-world circuit, the LED would blow as soon as you switch PA1 high. The resistor should be in series with the LED.

JW

Sm.16
Associate II

Hi,

im not getting anything from this,kindly someone please send me a code structure or step by step coding instructions for creating delay using timer with stm32f103r8.

it will be helpful.

S.Ma
Principal

Well, there are STM32 Cube library with many folders for existing boards. Hunt for a Nucleo using your STM32 family and look at sub folder TIMER examples.

Applications goal is to demonstrate the peripheral functionality, then you'll have to build the application delay desired functionality on top of it.

Otherwise, HAL_Delay() in msec unit.