cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO Toggling issue

Carter Lee
Associate III
Posted on September 08, 2017 at 15:55

Hi,

Now I'm currently working with GPIO control.

And I have an issue to control GPIO,

I came across there's not toggling when I use delay()

For example,

# GPIO toggling not working case

void delay(void)

{

volatile int i;

for(i=0; i<10000000; i++);

}

while (1)

{

GPIOG->BSRRL = GPIO_Pin_14;

delay();

GPIOG->BSRRH = GPIO_Pin_14;

delay();

GPIOG->BSRRL = GPIO_Pin_15;

GPIOG->BSRRH = GPIO_Pin_15;

GPIO_SetBits(GPIOG, GPIO_Pin_15);

GPIO_ResetBits(GPIOG, GPIO_Pin_15);

}

# GPIO  toggling working good case

void delay(void)

{

volatile int i;

for(i=0; i<10000000; i++);

}

while (1)

{

GPIOG->BSRRL = GPIO_Pin_14;

GPIOG->BSRRH = GPIO_Pin_14;

GPIOG->BSRRL = GPIO_Pin_15;

GPIOG->BSRRH = GPIO_Pin_15;

GPIO_SetBits(GPIOG, GPIO_Pin_15);

GPIO_ResetBits(GPIOG, GPIO_Pin_15);

}

Could you please let me know what does difference between them?

Why doesn't it toggling whithin delay() ?

9 REPLIES 9
Posted on September 08, 2017 at 17:55

If you are single stepping it might take a while. The delay might need to be tuned depending on how fast things are running, I chose a million to make sure the on/off would be human perceivable a dozens of MHz. Banging the lines up/down at a MHz is going to be imperceivable to the human eye.

Consider keeping your adventure in one thread, there's no value to having dozens of threads about materially the same evolution of what you're doing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 08, 2017 at 18:12

Hi!

The   '# GPIO  toggling working good case'      not includes any delay.

Which way you use to observe the toggling?  Do you have an oscilloscope?

Try to give a delay 10 times bigger and use this code.

while (1)

{

GPIOG->BSRRL = GPIO_Pin_14;

delay();

GPIOG->BSRRH = GPIO_Pin_14;

delay();

}

supposed that GPIOG pin 14  is initialized in pushpull output mode.(additionaly in your posted cases in maximum speed.)

Regards

vf

Posted on September 08, 2017 at 18:13

I can't understand what you are saying. Could you please let me know more clarify?

Posted on September 08, 2017 at 18:16

Yes, I've observed it in oscilloscope.

and I've tested with 10times.

while (1)

{

GPIOG->BSRRL = GPIO_Pin_14;

delay();

GPIOG->BSRRH = GPIO_Pin_14;

delay();

}

GPIOG->BSRRL = GPIO_Pin_15;

GPIOG->BSRRH = GPIO_Pin_15;

GPIO_SetBits(GPIOG, GPIO_Pin_15);

GPIO_ResetBits(GPIOG, GPIO_Pin_15);

That's working as my expectation, it still does not work with delay().

But If I remove delay() in there, then that's working as good, I can check with oscilloscope..

What kind of things should I have to consider to use GPIO toggling in maximum frequency (speed)?

Posted on September 08, 2017 at 18:52

Did you ever measured this delay? Is it too big? put a very small delay and observe in your oscilloscope.

Posted on September 08, 2017 at 19:06

Let me check to figure out with small delay.

BTW, I can't understand this, why does delay() affect to another gpio function?

Posted on September 08, 2017 at 20:19

The delay slows it down so you can physically see it blink. Oscilloscope not going to be helpful at 0.1 Hz

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 08, 2017 at 20:23

Don't know, you're not very good at explaining the context clearly. Slow signals will be visible to the eye, but difficult to see/sync on a scope.

Make the delay loop smaller, I pulled a million out of the air, try 100 or 1000

In the UK or South/North Korea?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Carter Lee
Associate III
Posted on September 09, 2017 at 09:16

I found it from oscilloscope that toggling signal.