cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure GPIO input?

hitsumen
Associate II
Posted on November 14, 2016 at 21:35

Good day,

What I want is:

If I put GND to GPIOD_4 I want to LED ON.

If high impedance then LED OFF.

I attached my schematic with CHRG pin connected to GPIOD_4.

Is it possible to pull up internally gpio?

I wrote some code:

void SysTick_Handler(void)

{

if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)){

STM_EVAL_LEDOn(LED3);

}

        else

{

STM_EVAL_LEDOff(LED3);

}

TimingDelay_Decrement();

}

void input_init(void){

  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

}

int main(void)

{

DBGU_Init();

 

printf(''\nSysTick_Configuration!'');

SysTick_Configuration();

 

STM_EVAL_LEDInit(LED3);

  

input_init();

  while(1);

}

2 REPLIES 2
Walid FTITI_O
Senior II
Posted on November 15, 2016 at 10:44

Hi

kovaliov.nikolaj,

If an input is configured with an internal pull-up, it will be high unless it is externally driven low.

The converse is true with pull-down inputs.

-Hannibal-

hitsumen
Associate II
Posted on November 17, 2016 at 09:40

Ah, i tested it on discovery board on which PD4 pin is connected to CS43L22 RESET pin which is R43 10k pulled low. So thats why it did not worked for me.

Modified code abit which worked.

void SysTick_Handler(void){

if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6)){

STM_EVAL_LEDOff(LED3);

}

else{

STM_EVAL_LEDOn(LED3);

}

TimingDelay_Decrement();

}

void input_init(void){

GPIO_InitTypeDef GPIO_InitStructure;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_Init(GPIOD, &GPIO_InitStructure);

}

int main(void)

{

DBGU_Init();

printf(''\nSysTick_Configuration!'');

SysTick_Configuration();

STM_EVAL_LEDInit(LED3);

  

input_init();

while(1);

}