AnsweredAssumed Answered

How to configure GPIO input?

Question asked by kovaliov.nikolaj on Nov 14, 2016
Latest reply on Nov 17, 2016 by kovaliov.nikolaj
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);
     
}

Attachments

Outcomes