cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO initialization/testing

nad
Associate II
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....

2 REPLIES 2
brazov22
Associate II
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

nad
Associate II
Posted on December 29, 2010 at 23:05

sorry, I made a mistake with the pines. 

it works now 

thank you