Normally keypresses are not direct change from one state to other , instead its a change with bit noise in between where the state seems undefined. To avoid the situation the common method is to recheck after certain delay if(PINState==Pressed) { delay(few_microsec); if(PINState==Pressed) { ActionKeyPress(); } } But if we are dealing with interrupt PIN_ISR() { setkeypressflag(); } main() { if (keypressflagset) if(PINState==Pressed) { DoKeyPressAction(); } } Now the most advanced one with timer or WatchdogTimer #pragma vector=PORT1_VECTOR __interrupt void P1_Function() { count=0; //Reset count TACTL|=TASSEL_2+MC_1+TAIE; //Start Timer0 with SMCLK clock source, UP mode and enable overflow interrupt state=(P1IN&BIT3)>>3; //Save the state of the switch P1IE&=~BIT3; //Disable interrupt on P1.3, now the Timer will take care of Debouncing P1IFG&=~BIT3; // Reset Port1 interrupt flag } #pragma vector=TIMER0_A1_VECTOR...
How Does STM32CubeIDE /*Configure GPIO pin : Pd3 */ GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOd, &GPIO_InitStruct); Now what is GPIOD and GPIO_InitStruct GPIOD the definition is deep inside CMSIS "Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f411xe.h" #define GPIOD ((GPIO_TypeDef *) GPIOD_BASE) and GPIOD_BASE declared in same file #define GPIOD_BASE (AHB1PERIPH_BASE + 0x0C00UL) Now GPIO_InitStruct is comes from the line GPIO_InitTypeDef GPIO_InitStruct = {0}; so the structure GPIO_InitTypeDef is as follows as defined in typedef struct { uint32_t Pin; /*!< Specifies the GPIO pins to be configured. This parameter can be any value of @ref GPIO_p...