Associate III
November 14, 2016
Question
How to configure GPIO input?
- November 14, 2016
- 2 replies
- 1375 views
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); }