Skip to main content
Visitor II
December 22, 2010
Question

GPIO initialization/testing

  • December 22, 2010
  • 2 replies
  • 704 views
Posted on December 22, 2010 at 23:02

hello, 

I just started with the STM8S-discovery .

can you tell me how I boot the pine 0,1,2 port B as input.

and how I'm doing the test on the value entered.

if (?????)

{

    instruction 1....

    This topic has been closed for replies.

    2 replies

    Visitor II
    December 23, 2010
    Posted on December 23, 2010 at 11:50

    i.e. for PORTC pin 0:

    #define BUTTON_PORT (GPIOC)

    #define BUTTON_PIN     (GPIO_PIN_0)

    /* -------------------------------------------------------------*/

    /* Check button status */

        if ((GPIO_ReadInputData(BUTTON_PORT) & BUTTON_PIN) == (u8)0x00)

        {

          /* Button is pressed */

          .....

          .....

        }

    by default all ports are configured as input floating. If you want you can configure them as input pull up at the beginning before doing the check on pin port status:

     /* Initialize I/O in Input Mode with pull up and no interrupt*/

      GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_PU_NO_IT);

    I suggest you to configure it as input pull up so when button is not presd pin0 is high, when you press button pin0 is low.

    brazov2

    nadAuthor
    Visitor II
    December 29, 2010
    Posted on December 29, 2010 at 23:05

    sorry, I made a mistake with the pines. 

    it works now 

    thank you