Skip to main content
minhthe2305
Associate II
October 29, 2009
Question

Set/Reset a pin

  • October 29, 2009
  • 3 replies
  • 1480 views
Posted on October 29, 2009 at 22:40

Set/Reset a pin

    This topic has been closed for replies.

    3 replies

    minhthe2305
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:28

    Hi,

    I am new with STM32F10X.

    Could anyone show me how to set/reset a pin. For example PA3 of STM32F103VBH6.

    I try GPIO_WriteBits / GPIO_SetBits / GPIO_ResetBits but it does not work?

    Thank you very much.

    johnfitzgerald9
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:28

    You may need to set up the GPIO pins with GPIOInit(). You need to enable the peripheral clock to the GPIO port with RCC_APB2PeriphClockCmd(). See main.c in the example GPIO_IOToggle in the peripheral library examples.

    Once you have that working, if you want, you can just use the set / reset and set registers,

    #define CLK GPIO_Pin_6

    GPIOF->BSRR = CLK; //clock high

    GPIOF->BRR = CLK; //clock low

    The advantage of these is that the same bit definition can be used to set or clear a pin depending on whether you write to the BSRR or BRR register.

    Hope this helps.

    minhthe2305
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:28

    Thanks for your replying.

    You are correct.

    What I did is use:

    - RCC_APB2PeriphClockCmd

    - GPIO_Init(GPIOA, &GPIO_InitStructure);

    - GPIO_SetBits + GPIO_ResetBits or GPIO_WriteBit

    To read the data port pin, I use GPIO_ReadInputDataBit.

    My code works now.

    Thanks again.