cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I am finding abnormal functioning of GPIO output while Toggling.I am getting Pulse of 0.2138s width everytime before my Desired Output(35microseconds) in STM32F401 Nucleo-64. Please Support.

Nchun.1
Senior

0693W00000AM1oBQAT.png0693W00000AM1o1QAD.png0693W00000AM1nwQAD.png0693W00000AM1nmQAD.png#include<NEW.h>

void delay();

void main()

{

SystemInit();

RCC->AHB1ENR |=1; /* Enabling clock for GPIOA port*/

GPIOA->MODER |=1<<24;/*General Purpose output function in PA12 Port*/

GPIOA->OSPEEDR|=1<<24;/*Medium speed */

  GPIOA->ODR |=(1<<12);/* Turning ON PA12pin */

  delay();/* 35 microseconds ON*/

  GPIOA->ODR &=~(1<<12);/* Turning OFF PA12 pin */

  while(1);

}

void delay()

{

 RCC->APB1ENR |=1<<0; /* TIM2 clock enabled*/

 TIM2->CNT=0;

 TIM2->ARR=500;

 TIM2->PSC=1;

 TIM2->CR1 |=1;

 while((!TIM2->SR & 1<<0));

 TIM2->SR=0;

}

5 REPLIES 5

Pulled-up the otherwise floating pin? Maybe your LA pulls it up?

Do you use the embedded bootloader?

Try some other pin. Try a 1kOhm pulldown.

JW

0693W00000AM86zQAD.pngProblem Solved after Connecting 1 Kohm Pull Down Resistor .

But output Pin is selected as Push-Pull(reset state) in GPIO_OTYPER by default. Why Pin is Floating i don't Understand.

0693W00000AM8KDQA1.pngThank you for ur Extended Support .

After reset, almost all pins including PA12 are set as Input in GPIO_MODER.

GPIO_OTYPER setting is pertinent only when the pin is turned to output, i.e. either set as Output in GPIO_MODER; or set as AF in GPIO_MODER and the controlling peripheral selected by GPIO_AFR set it as output (for example as when timer channel is set to Output Compare).

JW

Piranha
Chief II
while((!TIM2->SR & 1<<0));

And additionally this code is broken because of operator precedence and should be fixed by putting the correct braces. Currently it works only by coincidence and while only the UIF bit is used. And use the CMSIS defined names for bit-fields!

Thank you Piranha