Skip to main content
n239955_stm1_st
Visitor II
February 10, 2011
Question

on & off led

  • February 10, 2011
  • 5 replies
  • 1015 views
Posted on February 10, 2011 at 22:36

on & off led

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    May 17, 2011
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    trevor23
    Associate III
    May 17, 2011
    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++);

    }

    trevor23
    Associate III
    May 17, 2011
    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.
    Associate III
    May 17, 2011
    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.

    John F.
    Associate III
    May 17, 2011
    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.