cancel
Showing results for 
Search instead for 
Did you mean: 

on & off led

n239955_stm1_st
Associate
Posted on February 10, 2011 at 22:36

on & off led

5 REPLIES 5
trevor23
Associate III
Posted on May 17, 2011 at 14:24

Hi ajilforoushan.naeem,

I'm a bit confussed how this is supposed to toggle the LED. Assuming LED is on PA0 then shouldn't it be

while(1)

{

  GPIOA->BSRR = 1;       // LED on

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

  GPIOA->BRR = 1;        // LED off

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

}

Posted on May 17, 2011 at 14:24

Probably want to enable the GPIOA clocks, and configure the GPIO pins first.

Try looking at some of ST's example code in the firmware library.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
John F.
Senior
Posted on May 17, 2011 at 14:24

Either will do. It's not called the Bit Set Reset Register for nothing! The BSRR allows both operations.

trevor23
Associate III
Posted on May 17, 2011 at 14:24

I see, thanks. I wonder why the BRR resister is needed if both set and reset can be done using the BSRR register.

John F.
Senior
Posted on May 17, 2011 at 14:24

Hi Trevor,

The BRR and BSRR can be used together to set / reset a bit without having to change the value written to the register. This can save time compared to having to shift the bit up and down 16 places (for the BSRR). Might not mean much if writing in 'C' but can make fast assembler ''bit-bashing'' routines easier to write keeping values in registers.