2016-11-14 12:35 PM
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); }2016-11-15 01:44 AM
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-2016-11-17 12:40 AM
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);
}